Conditionals
Overview
Conditionals enable you to create dynamic test flows with different execution paths based on specified conditions. Harness AI Test Automation provides two types of control flow mechanisms:
Conditional Branching: Use IF, ELSE IF, ELSE, and END IF statements to build branching logic that executes different steps based on runtime conditions.
Guaranteed Execution: Use FINALLY blocks to ensure critical cleanup or verification steps always run at the end of a test, regardless of whether the test passes or fails.

Conditional statements
IF
Creates conditional branches in test execution based on specified conditions.
Description
Evaluates a condition that must return TRUE or FALSE. If the condition evaluates to true, the subsequent steps within the conditional block are executed.
Parameter option - Question
• User question: Prompts the user with a question during test execution • Text exists: Checks if specific text is present on the page • Text does not exist: Verifies that specific text is not present on the page • Use custom script: Accepts custom JavaScript that evaluates to TRUE or FALSE
Advanced options
• Use page HTML as context: When enabled, evaluates the condition against the page's HTML source • Disable AI code generation for this assertion: When enabled, causes Copilot to rely solely on visual inspection.
Return value
TRUE or FALSE
ELSE
Creates an alternative execution path.
Description
Used to create an alternative path for test execution when the preceding IF or ELSE IF conditions evaluate to FALSE
Parameter options
None
Advanced options
None
Return value
None
ELSE IF
Creates an alternative execution path.
Description
Evaluates an additional condition when the preceding IF or ELSE IF conditions evaluate to FALSE. If this condition returns true, the subsequent steps within this block are executed.
Parameter option - Question
• User question: Prompts the user with a question during test execution • Text exists: Checks if specific text is present on the page • Text does not exist: Verifies that specific text is not present on the page • Use custom script: Accepts custom JavaScript that evaluates to TRUE or FALSE
Advanced options
• Use page HTML as context: When enabled, evaluates the condition against the page's HTML source • Disable AI code generation for this assertion: When enabled, causes Copilot to rely solely on visual inspection.
Return value
TRUE or FALSE

END IF
Marks the end of a conditional block, completing the IF/ELSE IF/ELSE structure.
Description
Used to end a conditional block, marking the conclusion of IF/ELSE IF/ELSE statements
Parameter options
None
Advanced options
None
Return value
None
FINALLY
Ensures critical cleanup or verification steps are always executed, regardless of test outcome.
Description
Defines a block of steps that will always execute at the end of a test, whether the test passes or fails
Parameter options
None
Advanced options
None
Return value
None

Use FINALLY blocks to ensure your test environment is always left in a clean state, even when unexpected failures occur. This helps maintain test reliability and prevents side effects that could impact subsequent test runs.
Last updated
Was this helpful?