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
-
Go to the Test Navigator, select a test, and
double-click the test.
The test opens in the Test Contents pane.
-
Click a page or page request, and then click
.A prompt message is displayed to move the selected items to a new
If
block. -
Click Yes.
The
If
block is inserted before the selected item, and the item that you selected is moved underIf
in the Test Contents pane. -
Perform the following steps to add an
Else
block: -
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.
-
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. - Save the test.
Results
You have achieved the following results:
- You have added an
If
andElse
condition to a test. - You have performed the negate to operator, case-sensitive, and digit comparisons in a test.