Adding conditional logic

You can add an If-Else conditional logic around portions of a test, a compound test, or a schedule and you can make those portions of a test run when a specific condition is met. A conditional block can run portions of a test that depend on the value of a reference or field reference. The reference or field reference must exist in the test and precede the If-Else condition.

Before you begin

You must have recorded an HTTP test.

About this task

The test might already contain the test elements that you want to run. If the test contains the elements that you want to run, you must select the requests and then add an If condition. You can also create an empty conditional block at the end of the test or request. If the reference or field reference that the conditional block uses for input does not exist, you must create the references. See Creating a Reference or a Field Reference.

Procedure

  1. Go to the Test Navigator, select a test, and double-click the test.
    The test opens in the Test Contents pane.
  2. Click a page or page request, and then click Insert > Condition (If).
    A prompt message is displayed to move the selected items to a new If block.
  3. Click Yes.

    The If block is inserted before the selected item, and the item that you selected is moved under If in the Test Contents pane.

  4. Perform the following steps to add an Else block:
    1. Select the items under If to be moved to the Else block in the Test Contents pane.
    2. Right-click and select Insert > Condition (If) ELSE Block.
      A prompt message is displayed to move the selected items to a new If block.
    3. Click Yes.
      The Else block is inserted into the test. The item that you selected is moved under Else in the Test Contents pane and into the Else field in the Test Element Details pane.
  5. Add a condition to compare under Condition in the Test Element Details pane.

    Perform the following steps to add conditions in the Conditional (IF) Block Details.

    1. Click the Data Source option, in line with the First operand, and then select a data source to be compared with the string in the Second operand field.
      Alternatively, you can enter a value in the First operand field.
    2. Click the Operator, and then select the value from the list to indicate the basis of comparison of the two operands.
      You can select a value from the following list:
      • Equals
      • Contains
      • Starts with
      • Ends with
      • Less than
      • Less or equal
      • Greater than
      • Greater or equal
      • Matches regex
    3. Click the Data Source option in line with the Second operand, and then select a data source to be compared with the string in the First operand.
      Alternatively, you can enter a value in the Second operand field.
      Note: When you use the default value true in the First operand and Second operand to be compared with the strings and the Operator value is set to Equals, the conditional block is always processed. If you select the Matches regex operator to match the First operand and Second operand, then the Verify option is enabled. You can click Verify, to verify whether the regular expression finds a match in the data. If the regular expression does not find a match in the data source, a message is displayed.
  6. Select any of the comparison types, in the Test Element Details pane under Options, and perform the following steps:
    Option Description
    Negate the operator (NOT(op)) You can select the Negate the operator (NOT(op)) option to negate a condition when you perform a comparison. You can use the Negate the operator option to obtain an opposite result of any test condition. For example, if the result of any condition is true, the result returns to false, and if the result of any condition is false, the result returns to true.
    Case-sensitive comparison: You can select the Case-sensitive comparison checkbox to perform a case-sensitive string comparison. You can use Equals in the Operator to perform a case-sensitive comparison in a test.
    Compare as integers You can select the Compare as integers checkbox to perform a digit comparison in a test. You can view the comparison result returns to true or false when the two operands are integers in the If condition.
  7. Save the test.

Results

You have achieved the following results:

  • You have added an If and Else condition to a test.
  • You have performed the negate to operator, case-sensitive, and digit comparisons in a test.