This article explains the types of conditional steps and how they work in test execution for browser and mobile tests.
With conditionals, you can create flexible testing scenarios that run different test steps depending on the circumstances. Some examples include:
- Checking for an "Accept cookies" popup and clicking "OK" if it is present
- Using a different login flow if the test runs in a specific environment
- Running steps depending on the response from an API step
Type of conditional steps
At a minimum, a block of conditional steps must consist of an IF step and an END step. For additional scenarios, use ELSE IF and ELSE steps.
The test steps inside a conditional can include any number of steps or flows. You can also use conditionals within a reusable flow.
IF
Add an IF step to conditionally run steps based on:
For example, the IF step in the following screenshot checks if the "Accept all cookies" modal is present. If the IF step is true, the test clicks on the OK button. If the IF step is false, the test skips the conditional steps.
Using an IF step
ELSE IF
If you want to check for multiple cases within the same conditional block, add an ELSE IF step. Like IF steps, ELSE IF steps conditionally run steps based on:
For example, the steps in the following screenshot check if shipping totals for addresses in Alaska and Puerto Rico display the correct amount.
Using IF and ELSE IF steps
ELSE
If you want to run test steps in the event that the IF or ELSE IF steps are false, add an ELSE step.
For example, if your application used different login credentials for the staging environment, you could create a login flow that uses one set of credentials for staging and a different set of credentials for the other environments.
Using IF and ELSE steps in a flow
END
The END step is required for a conditional block. If you delete it and try to save your test, the mabl Trainer warns you that the conditional statement has no end step.
Running conditional steps
If a condition evaluates to true, the test steps within that conditional block run. Otherwise, mabl skips those test steps.
Skipped steps
Mabl skips test steps in the following circumstances:
- If an IF step evaluates to false, mabl skips the steps within the IF condition.
- If an IF ELSE step evaluates to false or follows an IF condition that was true, mabl skips the steps within the IF ELSE condition.
- If an IF or IF ELSE step evaluates to true, mabl skips the steps within an ELSE condition.
Learn more
For more information on how to add conditional steps in the mabl Trainer, see the article on using conditionals.