QA Focus

Jul 9 2008   1:51AM GMT

function junction: self-destructive pop-up

Sentinel627 Greg Annen Profile: Sentinel627


I use HP (formerly Mercury) QuickTest Professional for most of my functional test automation. This tool uses Windows’ VBScript as its internal scripting language. VBScript is relatively easy to learn and provides functions and sub-routines, basic date/time, string manipulation, math, user interaction, error handling, and regular expressions. This gives you the ability to extend the capabilities of QuickTest’s built-in functions by writing your own, which can then be associated with test scripts and called at run time. In fact, this capacity to call user-defined functions becomes the basis for most home-brewed automation frameworks.

One simple example of a user-defined function is a handy bit of code which pops up a customizeable message window that can be set to ‘self-destruct’ after a specified number of seconds. This is often more useful than the QuickTest msgbox() function which halts script execution until a required user action (pressing the OK button) is performed. Included with the function is a test harness which calls the function to demonstrate how it operates.

Copy and paste the code below into a text editor then save it as a file with a .VBS extension:

‘ ————————————- start here————————————–
Function popupMessage(msgText, waitSec, titleText, typeInt)
Dim WshShell, BtnCode
Set WshShell = CreateObject(“WScript.Shell”)
BtnCode = WshShell.Popup(msgText, waitSec, titleText, typeInt)
popupMessage = BtnCode ‘ allows processing in calling function
End Function

‘ vbscript test harness for function
‘ Valid codes for typeInt:”
‘ Value Button Value Icon
‘ —– ——————– —– ————
‘ 0 OK 16 Critical
‘ 1 OK, Cancel 32 Question
‘ 2 Abort, Ignore, Retry 48 Exclamation
‘ 3 Yes, No, Cancel 64 Information
‘ 4 Yes, No
‘ 5 Retry, Cancel
‘ The button values and icon values can be added together for composite effect.
‘ EG, typeInt of 4 + 32 (or, 36) means a message box with the ‘Question’ icon,
‘ and ‘Yes’ and ‘No’ buttons.

Dim msgText,waitSec,titleText,typeInt
msgText=”This is a message!”
titleText=”This Is A Pop-Up Window”
popupMessage msgText,waitSec,titleText,typeInt
‘ ————————————- end here————————————–

There are several ways to run this script (.VBS file) once you save it. (Don’t worry, it won’t damage anything!) The most common would be to right-click the script file in Windows Explorer and select ‘Open with’ to run in WScript, or ‘Open in MS-DOS Window’ (Windows 9x), or ‘Open in Command Window’ (Windows NT and Windows 2000) to run in CScript. Refer to the Microsoft Developer Network knowledgebase on VBScript for further information:

Our little script can also become part of a QuickTest Pro function library and called from within a QuickTest Pro script. I find it useful for debugging automated scripts when I want to see values of variables or just monitor execution progress.

There is a wealth of information on the web about the capabilities of VBScript, including a lot of sample code. So go ahead, be creative, have fun. Learn much. And AUTOMATE!

“Besides black art, there is only automation and mechanization.” – Federico Garcia Lorca

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: