Skip to content

Robust interactions

Chapter lab: Robustnessch10-web-robustness.zip · 27 KB

This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.

Download ch10-web-robustness.zip

Or fetch and unpack it from a terminal in VS Code:

Terminal window
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch10-web-robustness.zip && unzip -q ch10-web-robustness.zip && rm ch10-web-robustness.zip

Open the folder in VS Code with code rfe-ch10-web-robustness (or File → Open Folder…) and accept the recommended RobotCode and Python extensions. Then set it up:

Terminal window
uv sync
Terminal window
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Keep the environment active in every terminal where you run lesson commands.

Terminal window
poetry install --no-root

Python 3.13 or newer is required; uv installs it when it is missing.

Also needed for this lab

Install Node.js (an LTS release), then run once — it downloads a browser engine (large):

Terminal window
uv run rfbrowser init chromium
Terminal window
rfbrowser init chromium
Terminal window
poetry run rfbrowser init chromium

Start the RF Demo Shop in its own terminal and keep it running while you work:

Terminal window
uv run python demo_app/serve.py
Terminal window
python demo_app/serve.py
Terminal window
poetry run python demo_app/serve.py
What's inside
  • Directoryrfe-ch10-web-robustness/
    • Directory.vscode/
      • extensions.json
    • Directorychecks/
      • smoke.robot
    • Directorydemo_app/
      • api.py
      • serve.py
      • store.py
      • web.py
    • Directoryresources/
      • shop.resource
    • .gitignore
    • .python-version
    • LAB.md
    • pyproject.toml
    • README.md
    • requirements.txt
    • uv.lock

Real pages interrupt you: a promo overlay, a cookie banner, a tip that appears after load. A robust test handles the interruption explicitly — dismiss it, and wait for it to leave before continuing, so a later click isn’t intercepted.

The catalog page takes an ?overlay=1 flag that shows a dismissible promo overlay. Handle it.

Task 1 — Dismiss a promo overlay before continuing

Section titled “Task 1 — Dismiss a promo overlay before continuing”
Edit

Goal: create checks/robust.robot that opens the catalog with the overlay, asserts it is visible, dismisses it, and waits for it to detach before reading the catalog underneath.

Here is the same Wait For Elements State pattern over a different transition — waiting for the catalog title to appear after sign-in. Adapt it to the overlay.

Worked example — adapt it, don’t copy it

*** Settings ***
Library Browser
Resource ../resources/shop.resource
*** Test Cases ***
Wait For The Catalog To Appear
New Browser chromium headless=True
New Context
New Page ${BASE_URL}/login
Fill Text data-testid=login-username primary_user
Fill Text data-testid=login-password learning-password
Click data-testid=login-submit
Wait For Elements State data-testid=catalog-title visible
Get Text data-testid=catalog-title contains Catalog
Close Browser

Done when

the test waits for the overlay’s state with Wait For Elements State.

Hint 1

Open the overlay with New Page ${BASE_URL}/catalog?overlay=1, confirm it with Get Element States data-testid=promo-overlay contains visible, then Click data-testid=notice-close.

Hint 2

Wait for it to leave before continuing: Wait For Elements State data-testid=promo-overlay detached, then read the catalog underneath.

Solution
*** Settings ***
Library Browser
Resource ../resources/shop.resource
*** Test Cases ***
Dismiss The Promo Overlay
New Browser chromium headless=True
New Context
New Page ${BASE_URL}/login
Fill Text data-testid=login-username primary_user
Fill Text data-testid=login-password learning-password
Click data-testid=login-submit
New Page ${BASE_URL}/catalog?overlay=1
Get Element States data-testid=promo-overlay contains visible
Click data-testid=notice-close
Wait For Elements State data-testid=promo-overlay detached
Get Text data-testid=catalog-title contains Catalog
Close Browser
Run

Run:

Terminal window
uv run robot checks
Terminal window
robot checks
Terminal window
poetry run robot checks

Done when

the overlay is dismissed and the catalog is reachable underneath.

Check your understanding

Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.

  1. A promo overlay covers the page. A robust test…

    Show the answer

    Answer: dismisses it, then waits for it to detach before continuing — Close the overlay and wait for its element to detach, so later clicks aren't intercepted.

  2. Which keyword waits for an element to go away?

    Show the answer

    Answer: Wait For Elements State <loc> detached — Wait For Elements State <locator> detached (or hidden) waits for the element's state to change.

Key terms

Wait For Elements Statekeyword
Wait for an element to reach a state (visible/hidden/detached) before continuing.

All terms in the glossary →