Relevant for: GUI tests only
There are several ways to share or pass values from one action to other actions.
You can share a value that is generated in one action with other actions in your test, by storing the value in the data table. You can choose to place the value in either the Global sheet or the Action sheet. If you put the value in the Global sheet, other actions can then use the value in the Data pane as an input parameter. You can store a value in the Data pane by outputting the value to the global data table, or by using Data Table, Sheet and Parameter objects and methods in the Editor to add or modify a value.
If you create data table parameters or output value steps in your action and select to use the Current action sheet (local) option, be sure that the relevant run settings for your action are set in the Run tab of the Action Call Properties Dialog Box.
Suppose you are testing a flight reservation application. When a user logs into the application, the user's full name is displayed on the top of the page. Later, when the user purchases the tickets, the user must enter the name that is listed on his or her credit card.
Suppose your test contains three actions—Login, SelectFlight, and PurchaseTickets and the test is set to run multiple iterations with a different login name for each iteration. In the Login action, you can create a text output value to store the displayed name of the user. In the PurchaseTickets action, you can parameterize the value that is set in the Credit Card Owner edit box using the Data pane column containing the user's full name.
If you do not need to run multiple iterations of your test, or if you want the value you are sharing to stay constant for all iterations, you can use an internal, user-defined environment variable, which can be accessed by all local actions in your test.
For example, suppose you want to test that your flight reservation application correctly checks the credit card expiration date that the user enters. The application should request a different credit card if the expiration date that was entered is earlier than the scheduled flight departure date. In the SelectFlight action, you can store the value entered in the departure date edit box in an environment variable. In the PurchaseTickets action, you can compare the value of the expiration date edit box with the value stored in your environment variable.
As an alternative to using environment variables to share values between actions, you can use the Dictionary object. The Dictionary object enables you to assign values to variables that are accessible from all actions called from the test in which the Dictionary object is created, including both local and external actions.
To use the Dictionary object, you must first add a reserved object to the registry (in HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\) with ProgID = "Scripting.Dictionary".
HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary
After you add the reserved Dictionary object to the registry and restart UFT One, you can add and remove values to and from the Dictionary in one action, and retrieve the values in another action called from the same test.
Note: Some registry keys intentionally include previous company branding, due to backward compatibility considerations.
For more details, see VBScript Reference.
Suppose you want to access the departure date set in the SelectFlight action from the PurchaseTickets action. You can add the value of the DepartDate WebEdit object to the dictionary in the SelectFlight action as follows:
Then you can retrieve the date from the PurchaseTickets action as follows:
You can create a output value step in your action to pass the output of a step. Then in the Output Options, you can pass the output value to an action output parameter, which is then accessible to all subsequent or sibling actions.