Waiting on the network
Chapter lab: Forms and flows
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch09-web-flows.zip && unzip -q ch09-web-flows.zip && rm ch09-web-flows.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch09-web-flows.zip -OutFile ch09-web-flows.zip; Expand-Archive ch09-web-flows.zip -DestinationPath .; Remove-Item ch09-web-flows.zipOpen the folder in VS Code with code rfe-ch09-web-flows (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-ch09-web-flows/
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
The catalog search calls the shop’s API and updates the page when the response
arrives. With a network delay, the result count changes a moment later. The
wrong fix is a longer Sleep; the right fix is a getter assertion that
auto-waits for the value.
The catalog page takes a ?delay=<ms> flag that slows the search response, so
you can prove the wait is real.
Task 1 — Search with a network delay and let the assertion wait
Section titled “Task 1 — Search with a network delay and let the assertion wait”Goal: create checks/search.robot that signs in, opens the catalog with a
delay, searches, and lets the result-count assertion wait out the delay.
Here is the same wait over a different search term and delay. Adapt it to search
mug with an 800 ms delay.
Worked example — adapt it, don’t copy it
*** Settings ***Library BrowserResource ../resources/shop.resource
*** Test Cases ***Lamp Search Waits For The Network 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?delay=500 Fill Text data-testid=catalog-search lamp Click data-testid=search-submit Get Text data-testid=result-count == 1 Close BrowserDone when
the suite defines Search Waits For The Network.
Hint 1
Open the catalog with the delay flag: New Page ${BASE_URL}/catalog?delay=800,
then Fill Text data-testid=catalog-search mug and click search-submit.
Hint 2
Don’t Sleep — the getter assertion waits for you. Assert
Get Text data-testid=result-count == 1 and it retries through the delay.
Solution
*** Settings ***Library BrowserResource ../resources/shop.resource
*** Test Cases ***Search Waits For The Network 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?delay=800 Fill Text data-testid=catalog-search mug Click data-testid=search-submit Get Text data-testid=result-count == 1 Close BrowserTask 2 — Run it green
Section titled “Task 2 — Run it green”Run:
uv run robot checksrobot checkspoetry run robot checksDone when
the search settles at one matching product without a Sleep.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
The catalog search fetches results after a delay. The right fix is…
Auto-waiting getter assertions wait for the async result — never a fixed Sleep, which is either too short or too slow.
Show the answer
Answer: a getter assertion that auto-waits for the count — Auto-waiting getter assertions wait for the async result — never a fixed Sleep, which is either too short or too slow.
Searching
mugshould leave the result count at…Only Travel Mug matches
mug, so the count settles at 1 once the network responds.Show the answer
Answer: 1 — Only Travel Mug matches
mug, so the count settles at 1 once the network responds.
Key terms
- auto-waiting vs Sleepconcept
- Wait on what the page does (assertions), not a fixed duration.