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.
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.
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.
To remove a condition from a step, simply click <i class="fa fa-code-fork"/ > Remove Condition.
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:
return
a “truthy” JavaScript value in order for the step to execute, otherwise it will be skipped.window
, document
, etc.false
condition result.