Conditional testing refers to the common programming pattern where you perform one action, or a different one. It’s also known as control flow. Typically this is expressed as: If X, then Y, else Z.
Many of our users come into our chat asking how they can do “conditional testing” in Cypress.
The question is usually something like this:
I want to do something if the element exists, and do something different if the element doesn’t exist. How do I do that in Cypress?
This question may seem simple on the surface - but there is actually considerable complexity to doing this correctly. This question deserved much more than a simple answer, so we made the answer a part of the “Core Concepts” in our docs.
In the guide we talk about:
- Why this pattern is so complex
- Creating deterministic tests
- Avoiding writing flaky tests
- Strategies you can use today