> For the complete documentation index, see [llms.txt](https://docs.moropo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.moropo.com/creating-tests/advanced-use-cases/conditionals.md).

# Conditionals

Certain commands allow the use of conditional statements to allow the user to execute them only in certain cases.&#x20;

There are currently two supported conditional statements:

1. [#when](#when "mention")
2. [#while](#while "mention")

## `when`

The `when` statement allows a command to be executed only when one, or more, conditional statements are met.&#x20;

The check for the conditional statement is performed once upon evaluation of the command.

### Conditions

`when` supports four different conditions:

1. `visible` - run the command only `when` the proceeding selector element is visible
2. `notVisible` - run the command only `when` the proceeding selector element is NOT visible
3. `true` - run the command only `when` the given value is true or not empty
4. `platform` - run the command only `when` the platform is one of `android`|`ios`|`web`

These conditionals can be used individually or combined into a complex statement

### Supported Commands

The commands which can take the `when` statement are as follows:

* [runFlow](/creating-tests/commands/runflow.md)
* runScript (not yet supported by Moropo)

### Example

simple statement

```
- runFlow
    file: test.yaml
    when:
      visible:
        text: some text
```

complex statement

```
- runFlow
    file: test.yaml
    when:
      visible:
        text: some text
      notVisible:
         text: some different text
      true: ${SOME_VARIABLE == 'value'}
      platform: ios
```

## `while`

The `while` statement allows a command to  be executed only when one, or more, conditional statements are met.&#x20;

The check for the conditional statement is performed each time the conditional is not satisfied.

### Conditions

`while` supports four different conditions:

1. `visible` - run the command only `while` the proceeding selector element is visible
2. `notVisible` - run the command only `while` the proceeding selector element is NOT visible
3. `true` - run the command only `while` the given value is true or not empty
4. `platform` - run the command only `while` the platform is one of `android`|`ios`|`web`

These conditionals can be used individually or combined into a complex statement

### Supported Commands

The commands which can take the `while` statement are as follows:

* [repeat](/creating-tests/commands/repeat.md)

### Example

simple statement

```
- repeat
    commands:
      - scroll:
        direction: DOWN
    while:
      visible:
        text: some text
```

complex statement

```
- repeat
   commands:
      - scroll:
        direction: DOWN
    while:
      visible:
        text: some text
      notVisible:
         text: some different text
      true: ${SOME_VARIABLE == 'value'}
      platform: ios
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.moropo.com/creating-tests/advanced-use-cases/conditionals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
