Engine, context, page
Chapter lab: Browser foundations
This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.
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
Web testing with the Browser library rests on three layers:
- Browser — the engine process (Chromium here).
New Browser. - Context — an isolated session: its own cookies and storage.
New Context. - Page — a tab inside a context.
New Page.
Two contexts are two independent customers — separate logins, separate carts. This lesson proves that isolation against the bundled RF Demo Shop.
Task 1 — Start the RF Demo Shop and keep it running
Section titled “Task 1 — Start the RF Demo Shop and keep it running”The shop is a small local app. Start it in a terminal and leave it running:
uv run python demo_app/serve.pypython demo_app/serve.pypoetry run python demo_app/serve.pyIt serves the web shop on http://localhost:7272.
Done when
the shop answers on its port.
Task 2 — Prove two contexts are two isolated customers
Section titled “Task 2 — Prove two contexts are two isolated customers”Goal: create checks/browser_model.robot where one context signs in and sees
the catalog, then a second, fresh context visits the catalog and is bounced to
the login page — proving the sessions are isolated.
Here is the same isolation proof signed in as a different user. Adapt it.
(../resources/shop.resource gives you ${BASE_URL}.)
Worked example — adapt it, don’t copy it
*** Settings ***Library BrowserResource ../resources/shop.resource
*** Test Cases ***Two Sessions Stay Separate 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 New Context New Page ${BASE_URL}/catalog Get Url contains /login Close BrowserDone when
the isolation test passes with two contexts.
Hint 1
Sign the first context in as primary_user, then confirm the catalog with
Get Text data-testid=catalog-title contains Catalog.
Hint 2
Open a second New Context and New Page ${BASE_URL}/catalog without signing
in — a fresh session is bounced, so Get Url contains /login.
Solution
*** Settings ***Library BrowserResource ../resources/shop.resource
*** Test Cases ***Two Customers Have Isolated Sessions 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 New Context New Page ${BASE_URL}/catalog Get Url contains /login Close BrowserDone when
the isolation test passes with two contexts.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
Browser / Context / Page map to…
A Browser is the engine, a Context is an isolated session (its own cookies/storage), and a Page is a tab.
Show the answer
Answer: One engine process / one isolated session (cookies, storage) / one tab — A Browser is the engine, a Context is an isolated session (its own cookies/storage), and a Page is a tab.
Two customers in one test need…
Separate contexts isolate cookies and storage, so each behaves as a different signed-in customer.
Show the answer
Answer: two contexts — Separate contexts isolate cookies and storage, so each behaves as a different signed-in customer.
Key terms
- New Browser / New Context / New Pagekeyword
- Browser library: launch the engine, open an isolated session, open a tab.
- Browser libraryconcept
- Playwright-backed web automation; needs
rfbrowser init chromiumonce.