This article explains how to work with conditional steps in the mabl Trainer, including how to…
- Add a conditional step
- Replay conditional steps in the Trainer
- Implement IF…AND… logic
- Implement IF…OR… logic
- Exit a loop when a conditional passes
How to add a conditional step
In the mabl Trainer, take the following steps to add a conditional step:
- Click on + (Add step) > Conditionals.
- Select a specific conditional step type: IF, ELSE IF, ELSE
- If you are creating an IF or ELSE IF step, choose what you want to base the condition on: page element, custom find using CSS or XPath, JavaScript snippet, page URL, cookie, or variable value.
- Record the steps that you want to run if the condition evaluates to true.
Options for an IF step
When you add an IF step, the mabl Trainer adds an ELSE step and an END step by default.
- If you don't need the ELSE step, you may delete it.
- The END step is required. If you delete it, the mabl Trainer adds a warning icon to the conditional step indicating that the statement has no END step.
How to replay conditional steps in the Trainer
To confirm that your conditional steps work as expected in the mabl Trainer, you need to play them all together.
Do not play back conditional steps one at a time with the "step forward" button. The "step forward" button plays every step in the conditional block, regardless of whether the condition is true for the application under test.
Instead, take the following steps to replay conditional steps:
- Get your application in the proper state to run the conditional.
- Move the Trainer cursor to be right before the IF step.
- At the END step, click on More actions (...) > Play through here
When you replay the conditional steps, the Trainer evaluates whether the condition is true.
- If the condition is true, the Trainer plays the test steps.
- If the condition is false, the Trainer skips the test steps.
How to implement IF… AND … logic
To conditionally run steps when X and Y are true, take the following steps:
- Create an IF step to evaluate for the first scenario.
- Inside the IF step, add another IF step to evaluate for the second scenario.
- Inside the second IF step, record the steps that you want to run if both scenarios are true.
For example, in the following screenshot, the test clicks on a search result if it matches the correct categories: "Creating tests" and "Performance tests."
Using nested IF statements to implement IF… AND… logic
How to implement IF… OR… logic
You can set up for an IF… OR… scenario by taking the following steps:
- Create a variable called
either_situation
and assign it the value "false." - Create an IF step to evaluate for the first scenario.
- Add an ELSE IF step to evaluate for the second scenario.
- Inside both the IF and ELSE IF blocks, create a variable called
either_situation
and assign it the value "true." This action updates the value ofeither_situation
totrue
. - After the END step, add a new IF step that checks if the variable
either_situation
equals "true." - Inside the IF step, record the steps that you want to run if either scenario is true.
If your team is comfortable with maintaining JavaScript, you may also implement IF… AND… logic and IF… OR… logic using JavaScript steps.
For example of IF... OR... logic, the following screenshot shows a test that clicks the "SUBMIT" button if the file upload is either records.csv or roster.csv.
Implementing IF…OR…logic with variables and conditionals
How to exit a loop if a conditional statement is true
You can create a de facto while loop that exits the loop when a specific condition is met. See the article on Using loops > How to exit a loop early for more information.