Adding conditional logic

You can add IF-THEN conditional logic around portions of a test/compound test or a schedule, in this context, is used to refer to both VU Schedule and Rate Schedule to make those portions run if a specific condition is met.

Before you begin

A conditional block can run portions of a test depending on the value of a reference or field reference. The reference or field reference must exist in the test and precede the conditional block. If the reference or field reference that the conditional block uses for input does not exist, you must create the reference as explained in Creating a reference or field reference.

About this task

The test might already contain the test elements that are to be run. If the test does contain the elements to be run, you must select the requests in step 2 of the procedure, and click Insert. The following instructions explain how to add a conditional block that contains such requests.

Otherwise, you can create an empty conditional block at the end of the selected item (test or request). Click the object, and then click Add.

Procedure

  1. In the Test Navigator, browse to the test and double-click it.
    The test opens. You can also open a compound test or a schedule.
  2. Click a page or page request.

    The conditional block is inserted before the selected item. By completing step 5, you can move the selected items into the block.

  3. Press Shift or Ctrl when clicking to select multiple pages or requests to be moved into the block.
    In step 6, if you add an Else block, you can select one or more of these items to be moved into the Else branch.
  4. Right-click the item and select Insert > Condition (IF).
    A prompt Would you like to move selected objects into the new IF? is displayed.
  5. Click Yes or No.
    The If block is inserted into the test. If you click Yes, as shown in the example, the items that you selected are moved under If in the Test Contents area. The following example shows an If block with an HTTP test.test items copied under if statement
  6. To add an Else block:
    1. In the Test Contents area, under If, select the items to be moved to the Else block. Press Shift or Ctrl when clicking to select multiple items.
    2. Right-click and select Insert > Condition (IF) - ELSE Block.
      A prompt Would you like to move selected objects into the new ELSE? is displayed.
    3. Click Yes or No.
      The Else block is inserted into the test. If you click Yes, as shown in the example, the items that you selected are moved under Else in the Test Contents area and into the Else field in the Test Element Details area. The following example shows an If-Then-Else block with an HTTP test.test items copied under else statement
  7. In the Test Element Details area, under Condition, add conditions:
    1. Next to the First operand field, click Data Source, and then select a data source to be compared with the string in the Second operand field, or type a value in the First operand field.
    2. In the Operator field, indicate the basis of comparison of the two operands.
      Note that the two operands are strings.

      Starting from 9.1.1.1, you can use the Matches regex operator to match the operands. Click Verify to verify whether the regular expression finds a match in the data source. If there is a match, the Verify button is disabled. If there is no match, a message is displayed. If the regular expression is invalid, a message is displayed for that also.

    3. Next to the Second operand field, click Data Source, and select a data source to be compared with the First operand, or type a value in the Second operand field.
      When the defaults are used (both operand fields set to true and the Operator field set to Equals), the block is always processed.
  8. In the Test Element Details area, under Options, choose the required comparison type by selecting or clearing the check boxes.