> For the complete documentation index, see [llms.txt](https://docs.walnutai.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.walnutai.ai/test-and-quality-management/test-management/add-control-flow-conditional-statements/if-else.md).

# If / Else

If / Else enables a test case to follow different execution paths depending on whether a specified condition evaluates to true or false, allowing dynamic and logic-based test execution.

If certain steps need to be executed only when a condition is true (for example, login is successful), add them under the **If** section.\
If the condition is false, alternative steps can be added under the **Else** section.

* Click **"If / Else"** to add a conditional block in the test case.

<figure><img src="/files/zqznZYklWawJCXnd4Hht" alt=""><figcaption></figcaption></figure>

* **Set Condition for If -**&#x43;hoose how to set the condition:
  * **Element**
  * **Parameter**
* **Element -**&#x43;hoose **"Element"** when the condition depends on an object (UI element, text, etc.) on the screen.
  * From the dropdown, select the required option:
    * Conditions (is visible, is not visible)
    * Actions
    * Interactions(click, type, focus..)
      * **Example:**\
        To check if the **"Login Successful"** message is visible after clicking the login button:
        * If the message is visible → condition is true
        * If not → condition is false
* Select the required "**Object"** (stored using XPath / Playwright).
* Click "**Save"** to apply the condition.

<figure><img src="/files/mMLTKsQWv4Fr4oog9atc" alt=""><figcaption></figcaption></figure>

* **Parameter** - Choose **"Parameter"** when the condition depends on a value.

  * From the **1st dropdown**, choose an existing parameter OR Click "**Create"** to add a new parameter:
    * Enter Name (e.g., login\_status)
    * Enter Value (e.g., success)
    * Select Type (String, Number, etc.)
    * Click **Create**
  * From the **2nd dropdown**, select the comparison type\
    (equals, not equals, greater than, less than, contains, etc.)
  * Enter the comparison value (e.g., success)
    * **Example:**\
      To check if the login status is successful:
      * If login\_status = success → condition is true
      * If login\_status ≠ success → condition is false
  * Click "**Save"** to apply the condition.

  <figure><img src="/files/dE0vGaZa666hYE9XFKgL" alt=""><figcaption></figcaption></figure>

* **If (True Condition Steps)-**&#x41;dd the required steps under **If**.

  * These steps execute only when the condition is true.

  <figure><img src="/files/kk4gDS3Z0JBQ6CR3ViDI" alt=""><figcaption></figcaption></figure>

* **Else**

  * Add the required steps inside the "**Else"** section.
  * These steps execute only when the **If condition evaluates to false**.
    * **Example:**\
      If login is not successful:
      * Show error message
      * Retry login
      * Capture screenshot
  * If needed, update or modify the description
  * Click **"Save"** after changing description

  <figure><img src="/files/EWsksPgSOAoD78xNL0tU" alt=""><figcaption></figcaption></figure>

* **Else (False Condition Steps)-**&#x41;dd the required steps inside the **Else** section.

  * These steps execute only when the condition evaluates to false.

  <figure><img src="/files/kOZUhYTMNbWUfYlUxC4w" alt=""><figcaption></figcaption></figure>

* **End If**

  * **End If** marks the end of the If / Else condition.
  * It closes the conditional block and completes the flow.
  * If needed, update or modify the description
  * Click **"Save"** after changing description

  <figure><img src="/files/evgZwZI1q77IUo0CDu6A" alt=""><figcaption></figcaption></figure>

* **Example Flow**
  * If login is successful:
    * Perform dashboard actions
  * Else:
    * Show error and stop execution
  * After **End If**:
    * Continue with remaining test steps


---

# 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:

```
GET https://docs.walnutai.ai/test-and-quality-management/test-management/add-control-flow-conditional-statements/if-else.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
