One of the most frustrating experiences in QTP is watching a very long script run into an error, while you sit there helplessly, without any chance to effect the disappointing outcome. This means that a lot of very long test-runs have to be re-run, only because some of the test data / instructions weren’t accurate enough.
Sometimes QTP’s debugging capabilities are enough to fix the problems, and QTP 9.5 adds the very useful feature of “Maintenance run mode”; but usually we need a little something extra to make the script flow in the right direction.
VBScript offers a possible solution in the form if an InputBox, which allows the script to accept input from the user “on the fly”:
sDefault = "Some data"
sNewData = InputBox("Please enter new data", "Enter Data", sDefault)
'Here we can act upon the new user data
The new data can be input data for a field, identification strings for Descriptive Programming, or ever actual code we can perform using the Execute method. By placing these Input crossroads before critical stages in our script, we can assure we have some degree of influence over our script at real time.
However, the InputBox method has one huge drawback – it not only allows user input, it requires it. This means that if no one is around to input the data, the script will be stuck, forever waiting for an input that will never come. This kind of ruins the whole point of running an automated script.
Luckily, there’s a workaround. The WScript.Shell object has a Popup method, which can disappear after a given length of time. Using this, we can understand if the user want to enter a new input, and only then present the inputbox:
sDefault = "Some Data"
Set oShell = CreateObject("Wscript.Shell") 'Create the object
'Let’s find out if the user wan’t to input data! This popup will disappear after 5 sec.
iUserSelection = oShell.Popup ("Press OK if you want to enter new data", 5, "Select")
'iUserSelection holds the user’s selection. -1 means the popup closed without any user interaction
'So if iUserSelection is anything but -1, we should show the inputbox
If iUserSelection <> -1 Then sNewData = Inputbox ("Please enter new data", "Enter Data", sDefault)
The InputBox and Popup functions have much more options up their sleeve. You can loop InputBox up in QTP’s help, and if you want to know more about WScript.Shell popup method, you can read about it here.
Posted in General, QTP, Yaron Assa's Blog


Yaron Assa





June 5th, 2008 at 7:03 am
Its really useful
June 5th, 2008 at 7:23 am
Hi Yaron if we close the POP up it will let the script to show the inputbox to get the data. How can we avoid this?
June 5th, 2008 at 9:45 am
Change iUserSelection <> -1 to iUserSelection = 1
June 12th, 2008 at 3:54 pm
very good article
June 13th, 2008 at 2:00 pm
Good Article….
June 16th, 2008 at 4:22 pm
This article is good. But in automation testing this is not the right approach. The main advantange of Automation Testing is with out user interaction the scripts has to execute. If we incorporate InputBox statements in scripts then the user interaction must be required. After entering the data and clicking on the button then only we can proceed further.
June 16th, 2008 at 4:42 pm
RaghavVinu - You’re quite right; However, if you’ll read carefully, you’ll see that the described techniques don’t require the user’s input, and can very well run automatically and independently.
June 17th, 2008 at 10:28 am
It is very good work… awesome.
June 17th, 2008 at 2:23 pm
It’s gr8 work. Can you help me out, how to work with Sql Procedures in QTP? and how to work on with QTP Open Test Architecture?
August 17th, 2008 at 1:05 pm
works for me
September 3rd, 2008 at 7:05 pm
Good work. it’s very useful.