Conditional Step Execution

Execute a step conditionally based on defined parameters

Search our documentation:

Toggle Documentation Menu

Conditional Step Execution

Ghost Inspector gives you the ability to add conditions to your step execution during a test run. You can use this feature to create branches of step execution within your test, for instance if you need your test to respond slightly differently in a different environment or you wish to import another test under a certain condition.

Adding a Step Condition

To add a condition to a step, simply click the Add Condition link in the step header using the Test Editor. The step background will change to indicate that it is contained within a condition and the condition JavaScript editor will appear. You can specify your condition logic using JavaScript code. The code will be executed at runtime when the step is reached. The code must use return to return a true or false value. If the conditional logic returns true then the step will execute. If the conditional logic returns false then the step will be skipped.

Adding Conditional Steps in the Test Editor

Conditional Step Grouping

When two subsequent steps have conditional execution enabled and the condition statements are the same, then the steps will group under the same condition heading. This makes it simple to update the condition for multiple steps with the same condition at once. The simplest way to add a step within a current condition is to click Copy and then Paste Below or Paste Above on the existing conditional step.

If you have an existing step before or after a conditional step that you would like to group, click Add Condition and then copy and paste the same JavaScript condition statement into the new condition editor. As a result, the steps will group together under the same condition heading.

Grouped Conditional Steps in the Test Editor

To remove a condition from a step, simple click Remove Condition.

Conditional Evaluation Results

After test execution, any conditional step results will indicate the execution of the step condition and the value of the results in the test result:

Conditional Steps Results

Other Considerations