Forms and validation
Chapter lab: Forms and flows
This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch09-web-flows.zip && unzip -q ch09-web-flows.zip && rm ch09-web-flows.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch09-web-flows.zip -OutFile ch09-web-flows.zip; Expand-Archive ch09-web-flows.zip -DestinationPath .; Remove-Item ch09-web-flows.zipOpen 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:
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-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”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 BrowserResource ../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 BrowserDone 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 BrowserResource ../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 BrowserTask 2 — Run it green
Section titled “Task 2 — Run it green”Run:
uv run robot checksrobot checkspoetry run robot checksDone 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.
Testing the unhappy path means…
A blocked or invalid input should produce a clear, asserted error — the unhappy path deserves a first-class test.
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.
The blocked user should end up…
A blocked sign-in stays on /login and shows the
login-errorbanner.Show the answer
Answer: on the login page with an error banner — A blocked sign-in stays on /login and shows the
login-errorbanner.
Key terms
- negative testingconcept
- Assert the error a bad/blocked input produces — not just the happy path.