Skip to content

Timeouts

Chapter lab: Running with confidencech23-running-with-confidence.zip · 15 KB

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:

Terminal window
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.zip

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

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.

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

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 reached

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

Task 2 — Run it and watch the guard fire

Section titled “Task 2 — Run it and watch the guard fire”
Run

Run it:

Terminal window
uv run robot checks/guarded.robot
Terminal window
robot checks/guarded.robot
Terminal window
poetry run robot checks/guarded.robot

The test stops itself the moment the limit is hit:

uv run robot checks/guarded.robotrobot checks/guarded.robotpoetry run robot checks/guarded.robot
==============================================================================
Guarded
==============================================================================
Guarded Against Hangs | FAIL |
Test timeout 300 milliseconds exceeded.
------------------------------------------------------------------------------
1 test, 0 passed, 1 failed
==============================================================================

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.

  1. What does a [Timeout] do when exceeded?

    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.

  2. How do you cap every test in a suite?

    Show the answer

    Answer: Test Timeout in *** Settings *** — Test Timeout in 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.

All terms in the glossary →