> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stably.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditionals

> Execute different test actions based on page conditions and variables with Stably's infinitely nestable conditional logic.

<Note>
  This documentation is for **Stably Classic**. For the new Stably Web Editor, see [Stably Web Editor](/stably/stably-web-editor).
</Note>

Execute different actions based on a condition.

## How does it work?

Conditional actions can be used to execute two different branches of actions based on the current state of the page, as well as any variables defined. Conditional actions are infinitely nestable.
<Note>We currently only support locator-only auto-heal for conditional actions.</Note>

## Adding a conditional action

You can add a conditional action like you would any other action. First, enter your conditional statement. Stably AI will use the current state of the page, as well as any variables you have defined, to resolve the prompt to true or false when the test is run.

<Frame type="glass">
  <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/conditional/initial-state.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=76e9908b3697b9ed10f41238b2d85928" width="3020" height="1558" data-path="images/conditional/initial-state.png" />
</Frame>

**Adding nested actions to each branch**

You can add actions to the 'Then' and 'Else' action groups by clicking on the plus button inside each conditional block. You may also leave these empty.

## Running conditional actions

When running a conditional action, the executed path will be highlighted in green, and the logs will appear in the AI Logs sidebar.

<Frame type="glass" caption="This conditional action removed the analytics dashboard item">
  <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/conditional/resolved-conditional.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=f3bac3c940941f9d5bf5715224b7595e" width="2996" height="1560" data-path="images/conditional/resolved-conditional.png" />
</Frame>

## Recording inside a conditional

To record actions inside a conditional, you can move the cursor to a location inside a conditional block.

<Frame type="glass">
  <img style={{ height: '400px' }} src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/conditional/record-to.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=b6010225ebe661d32ae48c2a455580c0" width="926" height="1084" data-path="images/conditional/record-to.png" />
</Frame>

Then, any actions you do in the recorder will now be added at the location of the cursor.

## Seeing the execution path taken in executed tests

You can see the execution path taken in the test result page's Diff View tab, where the conditional action will show which branch was executed.

<Frame type="glass">
  <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/conditional/executed-path.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=cde237e8cf69cdca49dc8ff9e9566df9" width="2780" height="1068" data-path="images/conditional/executed-path.png" />
</Frame>

## Common use cases

* Cleanup tests that return the state of your website to how it was before a test or test suite was run. See [Run Settings](/run-tests/configuration/run-settings) for setup/teardown options.
* Conditionally defining variables

<Frame type="glass">
  <img src="https://mintcdn.com/stablyai/gQcjGEzeMU3Scby6/images/conditional/define-variable-example.png?fit=max&auto=format&n=gQcjGEzeMU3Scby6&q=85&s=06375815960995b05bf4380d1641dd9f" width="3006" height="1550" data-path="images/conditional/define-variable-example.png" />
</Frame>
