Conditional Steps
Conditional steps allow you to handle dynamic scenarios during test execution by adding logic that adapts to the application's state. These steps are particularly useful for interacting with elements like cookie banners, extending timeouts, or addressing reminders and prompts. While they can address known scenarios, they cannot handle completely unexpected pop-ups or behaviors.
Placement Required: Conditional steps must be placed at a specific point in the test sequence. They cannot handle completely unexpected pop-ups or interruptions.
What Are Conditional Steps?
Conditional steps use logic (e.g., if
statements) to execute specific actions based on the state of the application during a test run. This ensures your tests can adapt dynamically to various conditions.
For example, you can:
- Dismiss a cookie banner if it appears.
- Adjust timeouts for slower-loading pages.
- Handle prompts that ask users to take action, such as connecting their Google or Microsoft account.
How to Add Conditional Steps
- Open the specific test case where you want to add a conditional step.
- Identify the step where a conditional action is required.
- Add the appropriate Playwright code to handle the condition.
For more details on adding or editing test steps, refer to our Test Case Steps.
Conditional Step Examples
1. Skipping a Calendar Connection
If your application prompts users to connect their calendar but provides an option to skip, you can handle it with the following logic:
if page.is_visible("button:has-text('Skip')"):
page.click("button:has-text('Skip')")
2. Dismissing a Cookie Banner
For cookie banners that block interaction with the application, use the following logic:
if page.is_visible(".cookie-banner button"):
page.click(".cookie-banner button")
3. Handling Promotions or Sales Banners
If promotional banners appear, such as those on e-commerce platforms, you can dismiss them like this:
if page.is_visible(".promo-banner button.dismiss"):
page.click(".promo-banner button.dismiss")
4. Adjusting for Slow-Loading Pages
For pages that load slowly, conditionally extend the timeout:
if "slow-loading-page" in page.url:
page.set_default_timeout(10000)
Manual Setup Required: Qualiti’s AI currently doesn’t suggest conditional steps. Users must define them manually.