Adding an If step

You can insert the If logic in a test to make a set of steps run only if a specific condition is met.

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.

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 edit branch or create a new edit branch.
  3. Drag and drop the If element under any test step as required from the Flow catalog in the Catalog tab.
  4. Click the If step.
    The step details pane is displayed.
  5. Select the required mode from the Mode list:
    • UI
    • General
    Note:
    The default mode depends on where the If step is added. When the If step is added within a With step, it opens in UI mode. When it is added outside a With step, it opens in General mode.

    A confirmation dialog is displayed, indicating that switching modes clears the current step configuration.

  6. Click Yes.
    Note:
    • The default mode depends on where the If step is added. When the If step is added within a With step, it opens in UI mode. When it is added outside a With step, it opens in General mode.
    • You can switch between the available modes by selecting a different option from the Mode list.
    • If you switch modes after configuring the step, select the required mode and then click Yes in the confirmation dialog. The existing configuration is cleared and the step opens in the selected mode.
  7. You can perform the actions that are listed in the following table to configure an If step during a test run:
    Mode Action
    General
    Perform the following steps:
    1. Select a variable in the Value 1 list.
    2. In the Operator field, indicate the basis of comparison of the two operands. Note that the two operands are strings.
      The available operators are as follows:
      • Equals
      • Greater Than
      • Greater Than Equals
      • Equals variable
      • Less Than
      • Less Than Equals
      • Strict Equals
    3. Enter a value to be compared with the value of the selected variable in the Value 2 list.
    UI
    Perform the following steps:
    1. 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.

    2. Enter a property name such as Content, Id, or XPath of the object in the UI Property field.

      If you entered the property name correctly, the value of the property is displayed under Extracted Value.

      You can select the Code checkbox to enter the If statement in the text box.

      This allows you to write the condition in the text box in the JS mode.

  8. Click the Save icon to save the modifications.

Results

You have configured the If step to evaluate a condition during a test run. The steps within the If block are run only when the specified condition is met.

What to do next

You can run the test and view the results. See Running a Web UI test.