Skip to content

Forms and validation

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

This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.

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

A form is not done when the happy path works — it is done when the unhappy path is covered too. A blocked account, a wrong password, a missing field: each should produce a clear message, and each deserves a test that asserts it.

The RF Demo Shop has a blocked_user whose sign-in is refused with an error banner. Assert that path.

Task 1 — Assert the blocked-user error path

Section titled “Task 1 — Assert the blocked-user error path”
Edit

Goal: create checks/forms.robot that attempts a sign-in that must fail and asserts the error banner.

Here is the same error-path shape for a different failure — a wrong password. Adapt it to the blocked user.

Worked example — adapt it, don’t copy it

*** Settings ***
Library Browser
Resource ../resources/shop.resource
*** Test Cases ***
Wrong Password Is Rejected
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 wrong-password
Click data-testid=login-submit
Get Text data-testid=login-error contains failed
Close Browser

Done when

the suite defines Blocked User Sees An Error.

Hint 1

Sign in as blocked_user with the correct password learning-password — the credentials are valid, but the account is blocked.

Hint 2

The refusal shows in the error banner. Assert Get Text data-testid=login-error contains blocked.

Solution
*** Settings ***
Library Browser
Resource ../resources/shop.resource
*** Test Cases ***
Blocked User Sees An Error
New Browser chromium headless=True
New Context
New Page ${BASE_URL}/login
Fill Text data-testid=login-username blocked_user
Fill Text data-testid=login-password learning-password
Click data-testid=login-submit
Get Text data-testid=login-error contains blocked
Close Browser
Run

Run:

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

Done when

the blocked-user test passes — the error banner is asserted.

Check your understanding

Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.

  1. Testing the unhappy path means…

    Show the answer

    Answer: asserting the error a wrong or blocked input produces — A blocked or invalid input should produce a clear, asserted error — the unhappy path deserves a first-class test.

  2. The blocked user should end up…

    Show the answer

    Answer: on the login page with an error banner — A blocked sign-in stays on /login and shows the login-error banner.

Key terms

negative testingconcept
Assert the error a bad/blocked input produces — not just the happy path.

All terms in the glossary →