Aller au contenu principal

Conditional Step

The Conditional step evaluates a condition and executes one of two branches of child steps: the Then branch when the condition is true, or the Else branch when false.

When to Use​

  • Branching on a response status (e.g., different assertions for success vs. error)
  • Handling optional data (e.g., process a field only if it exists)
  • Validating pre-conditions before executing dependent steps
  • Building if-elseif-else chains for multi-case routing

Configuration​

Condition​

FieldDescription
Variable NameThe name of the variable to evaluate. When empty, the condition is always true (Then branch always executes).
Comparison ModeHow to compare the variable against the expected value
Expected ValueThe value to compare against. Not used for Existence/NonExistence modes.
String Compare ModeBinary (case-sensitive), CaseInsensitive, Loose (ignores spaces), or RegularExpression

Comparison modes:

ModeDescription
ExistenceVariable exists (has been set)
NonExistenceVariable does not exist
EqualsVariable value equals the expected value
ContainsVariable value contains the expected value
NotContainsVariable value does not contain the expected value
StartsWithVariable value starts with the expected value
EndsWithVariable value ends with the expected value
MatchesRegexVariable value matches the given regular expression pattern

Details​

FieldDescription
DescriptionFree-text field to document the purpose of the conditional branch.

Then Steps​

Child steps that execute when the condition is true. Add steps by dragging them into the Then Steps list.

Else Steps​

Child steps that execute when the condition is false. The Else branch folder only appears in the test tree when it contains at least one step.

Else-if chains: Place another Conditional step inside the Else branch to create else-if chains. The nesting hint in the UI reads: "Place another Conditional step inside the Else branch to create else-if chains."

Runtime Behavior​

At execution, the step evaluates the condition once. If true, all enabled steps in the Then branch run in order. If false, all enabled steps in the Else branch run (if any). The step returns Success after the branch completes.

If no condition variable is configured (Variable Name is empty), the condition is treated as true and the Then branch always executes.

Example: Branch on HTTP Status​

Step 1: Send Request (GET /api/orders/${OrderId})
→ stores status in the variable StatusCode, body in OrderBody

Step 2: Conditional
Condition:
Variable Name: StatusCode
Comparison Mode: Equals
Expected Value: 200

Then Steps:
Step 2.1: Assert
JSON Path on the response body
Path: $.status
Expected: "shipped"
Step 2.2: Data Transfer
response body, JSONPath $.trackingNumber → variable TrackingNumber

Else Steps:
Step 2.3: Conditional (else-if chain)
Condition:
Variable Name: StatusCode
Comparison Mode: Equals
Expected Value: 404

Then Steps:
Step 2.3.1: Assert
JSON Path on the response body
Path: $.error
Expected: contains "not found"

Else Steps:
Step 2.3.2: Run JavaScript
aethrix.info('Unexpected status for this order');

${OrderId} is a variable reference in a URL, substituted at send time; Variable Name fields take the name itself, written bare. A Json Path assertion reads the response, not a variable holding an earlier response — capture what you need with a Data Transfer step, then compare it with a Variable assertion (or put ${TrackingNumber} in another assertion's expected value, which is substituted too).

See Also​