Timeouts
Chapter lab: Running with confidence
This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.
Download ch23-running-with-confidence.zip
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch23-running-with-confidence.zip && unzip -q ch23-running-with-confidence.zip && rm ch23-running-with-confidence.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch23-running-with-confidence.zip -OutFile ch23-running-with-confidence.zip; Expand-Archive ch23-running-with-confidence.zip -DestinationPath .; Remove-Item ch23-running-with-confidence.zipOpen the folder in VS Code with code rfe-ch23-running-with-confidence (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.
Open in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.
What's inside
Directoryrfe-ch23-running-with-confidence/
Directory.vscode/
- extensions.json
Directorychecks/
- alpha.robot
- beta.robot
- unformatted.robot
- .gitignore
- .python-version
- LAB.md
- pyproject.toml
- README.md
- requirements.txt
- uv.lock
A keyword that hangs — a network call that never returns, an element that never appears — can freeze an entire run. A timeout caps how long a test (or a single keyword) may take. When the limit is exceeded, Robot Framework stops that test and fails it, and the run moves on instead of hanging forever.
Set [Timeout] on a test, or Test Timeout in *** Settings *** to cap every
test in the suite.
Task 1 — Stop a slow keyword with a timeout
Section titled “Task 1 — Stop a slow keyword with a timeout”Goal: create checks/guarded.robot with a test whose [Timeout] stops a
deliberately slow keyword — proving the guard fires instead of waiting the full
time.
Here is the same idea with a different limit and delay. Adapt it to a 0.3s
timeout over a 3s sleep.
Worked example — adapt it, don’t copy it
*** Test Cases ***Capped At One Second [Timeout] 1s Sleep 5s Log never reachedDone when
the test Guarded Against Hangs is stopped by its timeout.
Hint 1
Put the timeout first in the test, then a keyword that would take much longer:
[Timeout] 0.3s then Sleep 3s.
Hint 2
The Sleep never finishes — the timeout fires at 0.3s and fails the test with
a “Test timeout … exceeded” message. That is the guard working.
Solution
*** Test Cases ***Guarded Against Hangs [Timeout] 0.3s Sleep 3s Log never reachedTask 2 — Run it and watch the guard fire
Section titled “Task 2 — Run it and watch the guard fire”Run it:
uv run robot checks/guarded.robotrobot checks/guarded.robotpoetry run robot checks/guarded.robotThe test stops itself the moment the limit is hit:
It fails in about 0.3s with Test timeout 300 milliseconds exceeded — not
after the full 3s. A real hang would be caught the same way.
Done when
the run stops the slow keyword at the timeout.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
What does a
[Timeout]do when exceeded?Robot Framework stops the over-running test and fails it; the rest of the run proceeds instead of hanging.
Show the answer
Answer: stops the test and fails it, so the run continues — Robot Framework stops the over-running test and fails it; the rest of the run proceeds instead of hanging.
How do you cap every test in a suite?
Test Timeoutin the Settings section applies to every test;[Timeout]caps a single test.Show the answer
Answer:
Test Timeoutin*** Settings ***—Test Timeoutin the Settings section applies to every test;[Timeout]caps a single test.
Key terms
- [Timeout]concept
- Cap how long a test (or keyword) may run before it is stopped and failed.
- Test Timeoutconcept
- Settings-section timeout applied to every test in the suite.