For instance: If you want to know the current iteration number while running your scripts, then you may use automatic timeout msgbox using the below code.
Start_Time=Time
Set WshShell = CreateObject("WScript.Shell")
wshShell.Popup "Current Iteration No. "&Environment.Value("TestIteration"), 5 'Next step will not run until the time-out expires
SystemUtil.Run "Iexplore.Exe","http://www.google.co.in"
Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"
Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click
End_Time=Time
Msgbox Hour(End_Time-Start_Time) & ":" & Minute(End_Time-Start_Time) & ":" & Second(End_Time-Start_Time)
The above code has one drawback. When the msgbox is invoked, next step will not run until the specified msgbox's time-out expires.
Try the same scenario using Balloon Tool Tip code. The current iteration number will be displayed in System Tray and the script will not be stopped to display the tool tip.
icon_Path="C:\Documents and Settings\Desktop\6.ico" 'Choose any Icon file path from your PC. Make sure the file format should be .Ico.
Set oNtfy=DotNetFactory.CreateInstance("System.Windows.Forms.NotifyIcon","System.Windows.Forms")
Set oToolTip =DotNetFactory.CreateInstance("System.Windows.Forms.ToolTipIcon","System.Windows.Forms")
Set oIcon=DotNetFactory.CreateInstance("System.Drawing.Icon","System.Drawing",icon_Path)
Function fn_BalloonToolTip(vIterationNo)
oNtfy.Icon=oIcon
oNtfy.BalloonTipIcon=oToolTip.Info
oNtfy.Visible=True
oNtfy.Text = "QTP Info." 'Balloon Tool Tip Text Name
oNtfy.BalloonTipTitle = "Current Iteration No" 'Balloon Tool Tip Title
oNtfy.BalloonTipText="Current Iteration No. "&vIterationNo
oNtfy.ShowBalloonTip(5000) 'This line displays current iteration No in system Tray
End Function
Function fn_Kill_Balloon 'This function kills all the objects.
oNtfy.Dispose() 'After calling this method you will not see the balloon icon in system tray
Set oIcon =Nothing
Set oTool =Nothing
Set oNtfy=Nothing
End Function
Start_Time=Time
Call fn_BalloonToolTip(Environment.Value("TestIteration")) 'Calling balloon tool tip function
SystemUtil.Run "Iexplore.Exe","http://www.google.co.in"
Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"
Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click
Call fn_Kill_Balloon'Calling kill function
End_Time=Time
Msgbox Hour(End_Time-Start_Time) & ":" & Minute(End_Time-Start_Time) & ":" & Second(End_Time-Start_Time)
After invoking the fn_BalloonToolTip function, you will see the Balloon Tool Tip in your system tray as same as below,
In previous WScript code, the QTP script is waited until the msgbox timeout expires. Here QTP script will not wait for Balloon Tool Tip to be closed. The tool tip will remain in the system tray unless/until you call the fn_Kill_Balloon
I hope this technique will be useful for others also.
Please let me know if you have any questions in this.
thanks for this post
ReplyDeleteVisit my blog
Thanks
ReplyDeleteI tried using this code, and I was able to get the icon, but the balloon itself did not show? why is this?
ReplyDeleteHi, could you send the code which you tried, please?
ReplyDeleteE-mail: asiqahamed@yahoo.com
Thanks,
Asiq
Nice one!
ReplyDeleteFirst time it didn't work well.
I have to do some changes as per my scripts.
Now it working fine.
It's cool...
shrikalpesh@gmail.com
I could not get it to work. I copied the exact code on here and modified the Icon path to my icon location. Is there something on this script that needs to be changed before it can work properly?
ReplyDeletehi,
ReplyDeleteI'm able to get the tooltip and is being closed after 5secs, but the icon in tray is not getting removed, so whenever i run everytime new icon is adding, please let me know
Are you calling fn_Kill_Balloon function in your code?
ReplyDeleteThanks,
ReplyDeleteI have a question, if QTP stop suddently, so fn_Kill_Ballon can not be called, how we remove system tray.
Working fine for Me ... I have a question ... like to know how to remove the icons manually from the System tray if the script is terminated before calling fn_Kill_Ballon function. do we need to run the "fn_Kill_Ballon" function each and every time when we call "fn_BalloonToolTip" function?
ReplyDeleteHi, this function is working fine if I run using QTP.
ReplyDeleteI kept the same code in .vbs file and tried executing it by double clicking the .vbs (out side to QTP env). But, got an error as "Object Required: 'DotNetFactory'"... would like to implement this functionality in .vbs ... pls guide me in that regards.
How to run this function? Its not working for me..
ReplyDelete