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: Use the General mode to add if conditions to test steps.
    Perform the following steps:
    1. In the first column, click the Insert Variable icon Insert Variable to select a variable from the list or enter the variable name.
    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. In the third column, click the Insert Variable icon Insert Variable to select a variable from the list or enter the variable name in the Value field.

    For conditional statements, when you select a variable from the list, the variable is inserted without the ${} notation. When you concatenate a variable with a string, the variable is inserted in the ${variable_name} format.

    UI: Add conditional if statements for the UI elements directly from the Smartshot.
    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.

      You can replace a static property value with a variable by clicking the Insert Variable icon Insert Variable. During a test run, UI elements can be targeted dynamically based on the variable value.

      When you select a variable from the list, the variable is inserted without the ${} notation. When you concatenate a variable with a string, the variable is inserted in the ${variable_name} format.

    2. Optional: Click the Click here to add relative to , specify the relative location in the Location field, and specify the relative object in the UI Object field.
    3. Optional: Click Click here to add alternative identifier, and select a target object from the list in the Target 2 field.

      Alternatively, you can drag and drop an element from the Smartshot view.

    4. Optional: 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.