---
title: "Conditional testing and control flow in Cypress"
url: "https://www.cypress.io/blog/conditional-testing"
description: "How to write conditional tests and control flow in Cypress"
---

[Blog](/blog/)[Education: Tutorials](/blog/tag/tutorials)

# Conditional testing and control flow in Cypress

October 30, 2017

•

By Brian Mann

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](https://on.cypress.io/chat?ref=cypress-io.ghost.io) 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](https://docs.cypress.io/?ref=cypress-io.ghost.io).

**In the guide we talk about:**

-   Why this pattern is so complex
-   Creating deterministic tests
-   Avoiding writing flaky tests
-   Strategies you can use today

[Please check out our new guide for Conditional Testing](https://on.cypress.io/conditional-testing?ref=cypress-io.ghost.io).