Login   /   Register

Changing Script Input Data “On the Fly”

Rate this article
     2 votes, average: 3 out of 52 votes, average: 3 out of 52 votes, average: 3 out of 52 votes, average: 3 out of 52 votes, average: 3 out of 5
Loading ... Loading ...
June 4th, 2008 by Yaron Assa

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

image

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)

image image

 

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

11 Responses to “Changing Script Input Data “On the Fly””

  1. prince3105 Says:

    [-]

    Its really useful

  2. prince3105 Says:

    [-]

    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?

  3. Yaron Assa Says:

    [-]

    Change iUserSelection <> -1 to iUserSelection = 1

  4. rajendra.penumalli Says:

    [-]

    very good article

  5. Raj_Singh Says:

    [-]

    Good Article….

  6. RaghavVinu Says:

    [+]

    This article is good. But in automation testing this is not the right approach. The main advantange of Automation Testing is with ... ...

  7. Yaron Assa Says:

    [+]

    RaghavVinu - You're quite right; However, if you'll read carefully, you'll see that the described techniques don't require the use... ...

  8. Challa Says:

    [-]

    It is very good work… awesome.

  9. sankar.p Says:

    [-]

    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?

  10. sqasim Says:

    [-]

    works for me

  11. burnt Says:

    [-]

    Good work. it’s very useful.

Leave a Reply

You must be logged in to post a comment.

This article was viewed 1235 times