Assigning an object property to a test variable

You can use the value of a UI object property and assign the value to a test variable in the Web UI tests. The process of assigning a variable to an object property is called a variable assignment.

Before you begin

You must have completed the following tasks:
  • Ensured that you are assigned a Team Space Owner, Project Owner, or Member with a Tester role to create or edit a test resource.
  • Read and understood the information in Edit branch overview and Create or select an Edit branch.
  • Ensured that your project contains a Web UI test.

About this task

You can modify the value that is being assigned to the variable by using a regular expression. 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 run the test. You can view the variable value User Documentation in the Functional Report.

Procedure

  1. Click the Edit button displayed on the Test Editor page.

    The Edit button appears only when no active edit branch is selected.

    Alternatively, right-click the test in the test navigator panel and select Edit.

    The Edit branch dialog is displayed.
    If the Edit branch dialog is not displayed, then go to step 3.
  2. Select an existing branch or create a new branch.
  3. Drag the Assign statement from the Catalog > UI pane and drop it under a test step as required.
    The Assign step is inserted.
  4. Click the Assign step.
    The step details pane is displayed.
  5. Hover over a UI element in the Smartshot view, right-click, and then select Use this element as a step target.
    Alternatively, you can drag and drop a UI element from the Smartshot view to the Object identified by section.

    The UI Object type is identified.

  6. Enter a property name such as Content, Id, or Xpath of the object that must be used for variable assignment in UI Property.
    If you entered the property name correctly, the value of the property is displayed under Extracted Value.
  7. Select one of the following options from the Assign to list:
    • Select an existing variable.
    • Select Add new variable, enter a name for the variable, and then click Add.
  8. Optional: Select the Modify value checkbox.
    The Regex field is displayed.
  9. Optional: Enter a regular expression to extract a substring from the value of the object property in Regex.
    For example, if you want to extract the last 3 digits from 560064, which is a Zip code, and assign it to the variable 'zipCode_3', you can use the expression [0-9]{3}.
  10. Close the step details pane.
  11. Click the Save icon to save the modifications.

Results

You have assigned the value of a UI object property to a test variable in the Web UI test.
Note:
The variables that you created in Test Editor are listed in the Variables section of the Configure settings and data pane as test variables.

What to do next

You can perform the following tasks:
  • Run the test in Test Editor and view the Functional Report to verify the test steps with the variable assignment. See Running a Web UI test.
  • Start the test run from the Execution page, and in the Execute test asset dialog, navigate to the Configure settings and data option on the Test Editor page to view the Test variables defined in the test. See Configuring a run of a Web UI test and Variables.