Assigning a test variable to an object property

You can use the value of a UI object property and assign the value to a test variable in all the UI tests created for Android, iOS, hybrid, or native mobile applications, desktop applications, and web applications. The process of assigning a variable to an object property is called a variable assignment.

Before you begin

To create a variable assignment, you must have declared a variable. See Declaring and assigning test variables.

About this task

You can extract a substring from the content of an object property by using a regular expression and then assign the substring to a variable. For example, you can extract User Documentation from the Content property of a hyperlink, and then assign the string to the trimVar variable. Further, you can include trimVar in the subsequent steps and execute the test. You can view the variable value User Documentation in the unified report.

You can also use variable assignment to check if an object exists and return true or false to the variable. Further, based on the value of the variable, you can choose to branch the test steps by using an If-Else block. For example, you can assign the check_state variable to the Object's property > Exist property of the Login button, and then use conditional statements to either log in or not.

You can create variable assignments in all the UI tests that are created for Android, iOS, hybrid or native mobile applications, desktop applications, and web applications.
Note: When you run a test from the mobile client on mobile devices, it uses the same values that you used during recording. If you modify the test script and create a dataset or variable, or if you add a condition, a loop, custom code, references or add other statements, they are not taken into account by the mobile client at run time. To verify that the initial recorded values are substituted with variable data, you must initiate the test run from Rational® Functional Tester.

Procedure

  1. Open the test, and in the Test Contents area, select a test element.
  2. Select Insert > Variable Assignment.
    The Test Editor window opens and lists the variables available to the test.
  3. Select the variable for which you want to assign a value, and then click OK.
    A variable assignment statement is inserted before the selected element.
  4. Select UI object property in the Set to box in the Variable Assignment Details area.
  5. Select the values for the following fields:
    Option Description Action
    Graphic object

    This option lists the objects that you can select for variable assignment.

    Depending on the graphic object that you select, the corresponding options are displayed in the other UI elements of the Variable Assignment Details panel.

    Select an object from the list.
    Object identified by This option lists the identifiers of the selected object. Select an identifier such as Xpath or Id of the object from the list.
    Object location

    This option lists the possible locations of the selected object.

    For example, the Login button can be below a checkbox on a page when you recorded the test.

    Select the location of the object from the options provided in the list and then provide the values.

    The default value is (automatic detection).

    Object's property This option lists the properties of the selected object that must be used for variable assignment. Select one of the following options from the list:
    • Select a property such as Title, Content, or Xpath of the object that must be used to extract the value using a regular expression.

      Go to step 6.

    • Select Exist to verify whether the selected object exists and returns the value to the variable.

      Go to step 7.

    The values of the properties displayed in the lists are different for web, Android and iOS apps.
  6. Enter a regular expression to extract a substring from the value of the object property in Extract value using Regex.
    For example,
    User(.*)
  7. Save the test.
    A set statement is added to the test with the value you chose.
    For example, the following set statement is added if you selected Extract value using Regex:
    Variable 'trimVar' is set to 'Extract value using regex User(.*)' from property 'Content' of Hyperlink whose Content is User Documentation located at position 1
    If you selected Exist, the following set statement is added:
    Variable 'trimVar' is set from property 'Exist' of Heading H4 whose Content is User Documentation