Skip to content

Engine, context, page

Chapter lab: Browser foundationsch08-web-foundations.zip · 27 KB

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:

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

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

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

Engine, context, pagetree diagram. Two contexts are two isolated customersBrowserNew Browser (the engine)BrowserContextNew Context (own cookies)PageNew Page (a tab)Two contexts are two isolated customers

Task 1 — Start the RF Demo Shop and keep it running

Section titled “Task 1 — Start the RF Demo Shop and keep it running”
Run

The shop is a small local app. Start it in a terminal and leave it running:

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

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

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

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

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

  1. Browser / Context / Page map to…

    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.

  2. Two customers in one test need…

    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 chromium once.

All terms in the glossary →