Sometimes, data that is collected during a run session might be needed for later use. For example, suppose that Application Under Test (AUT) is a mobile operator management system. We could begin by executing a customer creation process, during which a customer ID is assigned automatically by the system. We then proceed with the other operations, such as selecting a phone number, an IMEI, credit card details, and so on. Later, we may wish to retrieve the customer records and update some personal data such as the mailing address. For this purpose, we will keep the customer ID in the global datasheet, so that any action that is executed, which can be referenced later (for example, one that performs a customer search), will have access to the data.
Proceed with the following steps:
CustomerID
, to the global sheet with the following code written in the code editor inside Action1
:Dim CustomerID DataTable.GlobalSheet.AddParameter "CustomerID", "990011234" CustomerID = DataTable("CustomerID") Print Environment("ActionName") & ": " & CustomerID
The following dialog will open:
Action2
will appear in the Solution Explorer window and open on the code editor's MDI region:CustomerID
parameter from the global sheet with the following code inside Action2
:Dim CustomerID CustomerID = DataTable("CustomerID") Print Environment("ActionName") & ": " & CustomerID
The result of this code in the UFT's console is shown in the following screenshot:
When we run the test, UFT first executes Action1
, and a new parameter named CustomerID
will be added to GlobalSheet
(a property of the DataTable
object that refers to the GlobalSheet
object) with the value given by the second parameter.
DataTable.GlobalSheet.AddParameter "CustomerID", "990011234"
We then immediately assign a variable with the retrieved value and print it to the console (for illustration purposes, we also concatenate the current action's name from the Environment
object's built-in variables).
CustomerID = DataTable("CustomerID") Print Environment("ActionName") & ": " & CustomerID
Next, UFT executes Action2
same as Action1
.
There are other alternative ways of keeping and sharing data during a run session. The simplest is by using public variables declared in a function library attached to the test. The disadvantage of this approach is that these variables must be declared in advance and they are hard coded, but the nature of automation often demands more flexibility to manage such data.