> 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2FDaErd4PhcqjuDqAckdbe%2Fimage.png?alt=media&amp;token=dbac5305-7b8e-444e-a638-515c8d829de4" 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2F8kdzkFS8E5D9wfCI9so6%2Fimage.png?alt=media&amp;token=bcb87846-c2ec-4853-a324-8ab6c1121b27" 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2FztVdtiiwuZm8lSXzhDIL%2Fimage.png?alt=media&amp;token=aeba20d0-aa86-460c-b720-2b32d762c3be" 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2F9PjwnOWoBZ50s5N4ijcU%2Fimage.png?alt=media&amp;token=63f383f0-e0c8-49d2-b80f-5a703da6b682" 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2FTSilBWU8oYfoWQNmZHZO%2Fimage.png?alt=media&amp;token=079c3e8e-d147-46f0-baee-19220c1180d1" 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2FP5s7au2YAYM4quOGDiBT%2Fimage.png?alt=media&amp;token=2a418cbf-c4bf-4bbc-a1b3-648c302bc11b" 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="https://295337183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9aroNmDWVJAmMjkdy0hx%2Fuploads%2F9ns9rZPiL588FctS7XlZ%2Fimage.png?alt=media&amp;token=b4e51951-b456-461b-ae45-1aedd2a15af8" 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
