Skip to content

Waiting on the network

Chapter lab: Forms and flowsch09-web-flows.zip · 27 KB

This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.

Download ch09-web-flows.zip

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

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

Open 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:

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-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”
Edit

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 Browser
Resource ../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 Browser

Done 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 Browser
Resource ../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 Browser
Run

Run:

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

Done 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.

  1. The catalog search fetches results after a delay. The right fix is…

    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.

  2. Searching mug should leave the result count at…

    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.

All terms in the glossary →