Skip to main content

authentication Scenario 3 — Conditional Login Check with Fallback

Written by RTILA X Engineering Team

Beginner ~4 min

What You'll Learn

Branch logic based on authentication state

Real-World Use Case

Reducing unnecessary login steps

LIVE DEMO

Conditional Auth State

The page defaults to logged out. A fallback branch can navigate to a known login flow when needed.

EXPECTED OUTPUT

Fallback Profile Data

label value
Email user@test.com
Role Admin
Member Since 2024-03-15
RTILA X PROJECT JSON

RTILA X Automation Project

conditional-login-fallback.json
    {
  "name": "Conditional_Login_With_Fallback",
  "settings": {
    "urls": [
      "https://learn.rtila.com/scenarios/authentication/3"
    ]
  },
  "datasets": {
    "profile_data": {
      "item_selector": "css=.dashboard-content table tr",
      "properties": [
        {
          "name": "label",
          "type": "text",
          "selector": "css=td:first-child"
        },
        {
          "name": "value",
          "type": "text",
          "selector": "css=td:last-child"
        }
      ]
    }
  },
  "commands": [
    {
      "command": "goto",
      "params": {
        "url": "https://learn.rtila.com/scenarios/authentication/3"
      }
    },
    {
      "command": "if",
      "params": {
        "condition": {
          "type": "element_visible",
          "selector": "css=.logout-btn"
        },
        "then": [
          {
            "command": "extract_data",
            "params": {
              "dataset": "profile_data"
            }
          }
        ],
        "else": [
          {
            "command": "goto",
            "params": {
              "url": "https://learn.rtila.com/scenarios/authentication/1"
            }
          },
          {
            "command": "wait_for_selector",
            "params": {
              "selector": "css=#login-form"
            }
          },
          {
            "command": "fill",
            "params": {
              "selector": "css=#username",
              "value": "user@test.com"
            }
          },
          {
            "command": "fill",
            "params": {
              "selector": "css=#password",
              "value": "secret"
            }
          },
          {
            "command": "click",
            "params": {
              "selector": "css=#login-btn"
            }
          },
          {
            "command": "wait_for_selector",
            "params": {
              "selector": "css=.dashboard-content"
            }
          },
          {
            "command": "goto",
            "params": {
              "url": "https://learn.rtila.com/scenarios/authentication/3"
            }
          },
          {
            "command": "extract_data",
            "params": {
              "dataset": "profile_data"
            }
          }
        ]
      }
    }
  ]
}
  

RTILA X Concepts

This shows the full if/else pattern. Checking for a .logout-btn reveals whether the browser session is authenticated, and the else branch performs the required login flow.

Did you complete this scenario?

Ready to run this automation?

Copy the project JSON above, open RTILA X, create a new project, and paste it.

This scenario covers 3 RTILA X commands and is referenced in 2 learning articles.

Continue Learning

Was this helpful?