Locators and interactions
Chapter lab: Browser foundations
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Download ch08-web-foundations.zip
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch08-web-foundations.zip && unzip -q ch08-web-foundations.zip && rm ch08-web-foundations.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch08-web-foundations.zip -OutFile ch08-web-foundations.zip; Expand-Archive ch08-web-foundations.zip -DestinationPath .; Remove-Item ch08-web-foundations.zipOpen the folder in VS Code with code rfe-ch08-web-foundations (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-ch08-web-foundations/
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
To drive a page you need to find elements and act on them. The Browser
library finds elements with selectors; the most reliable is a test id —
data-testid=login-submit. Test ids are added for automation and survive
restyles, where CSS classes and layout do not.
Acting is two keywords for now: Fill Text types into a field, and
Click presses a button or link.
headless=True on New Browser runs the engine without opening a visible
window — the norm for automation and CI. Drop it to watch the run in a real
browser while you debug.
Task 1 — Sign in using data-testid locators
Section titled “Task 1 — Sign in using data-testid locators”Goal: create checks/login.robot that signs primary_user into the shop
using test-id locators, and confirms the catalog appears.
Here is the same sign-in as a different user. Adapt it to primary_user.
Worked example — adapt it, don’t copy it
*** Settings ***Library BrowserResource ../resources/shop.resource
*** Test Cases ***Reviewer Signs In New Browser chromium headless=True New Context New Page ${BASE_URL}/login Fill Text data-testid=login-username reviewer_user Fill Text data-testid=login-password learning-password Click data-testid=login-submit Get Text data-testid=catalog-title contains Catalog Close BrowserDone when
the suite uses Fill Text and Click on test-id locators.
Hint 1
Fill both fields by their test ids: Fill Text data-testid=login-username primary_user
and Fill Text data-testid=login-password learning-password.
Hint 2
Click data-testid=login-submit to submit, then confirm you landed with
Get Text data-testid=catalog-title contains Catalog.
Solution
*** Settings ***Library BrowserResource ../resources/shop.resource
*** Test Cases ***Primary User Signs In 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 Get Text data-testid=catalog-title contains Catalog Close BrowserTask 2 — Run it green against the shop
Section titled “Task 2 — Run it green against the shop”With the shop running, run:
uv run robot checksrobot checkspoetry run robot checksDone when
the test Primary User Signs In passes.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
Why prefer
data-testid=locators over CSS classes?Test ids are added for testing and survive redesigns; styling selectors break when the UI is restyled.
Show the answer
Answer: They are stable across restyles — classes and layout change, test ids do not — Test ids are added for testing and survive redesigns; styling selectors break when the UI is restyled.
Which keyword types into a field?
Fill Text <locator> <value>fills an input;Clickpresses buttons and links.Show the answer
Answer:
Fill Text—Fill Text <locator> <value>fills an input;Clickpresses buttons and links.
Key terms
- data-testid locatorconcept
- Stable Browser-library selector:
data-testid=login-submit. - Fill Text / Clickkeyword
- Type into a field / press a button or link.