Robust interactions
Chapter lab: Robustness
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:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch10-web-robustness.zip && unzip -q ch10-web-robustness.zip && rm ch10-web-robustness.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch10-web-robustness.zip -OutFile ch10-web-robustness.zip; Expand-Archive ch10-web-robustness.zip -DestinationPath .; Remove-Item ch10-web-robustness.zipOpen 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:
uv syncpython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython -m venv .venv.venv\Scripts\Activate.ps1pip install -r requirements.txtKeep the environment active in every terminal where you run lesson commands.
poetry install --no-rootPython 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):
uv run rfbrowser init chromiumrfbrowser init chromiumpoetry run rfbrowser init chromiumStart the RF Demo Shop in its own terminal and keep it running while you work:
uv run python demo_app/serve.pypython demo_app/serve.pypoetry run python demo_app/serve.pyWhat'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”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 BrowserResource ../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 BrowserDone 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 BrowserResource ../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 BrowserTask 2 — Run it green
Section titled “Task 2 — Run it green”Run:
uv run robot checksrobot checkspoetry run robot checksDone 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.
A promo overlay covers the page. A robust test…
Close the overlay and wait for its element to detach, so later clicks aren't intercepted.
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.
Which keyword waits for an element to go away?
Wait For Elements State <locator> detached(orhidden) waits for the element's state to change.Show the answer
Answer:
Wait For Elements State <loc> detached—Wait For Elements State <locator> detached(orhidden) 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.