Skip to content

Speed as a strategy

Chapter lab: API in practicech12-api-in-practice.zip · 17 KB

This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.

Download ch12-api-in-practice.zip

Or fetch and unpack it from a terminal in VS Code:

Terminal window
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch12-api-in-practice.zip && unzip -q ch12-api-in-practice.zip && rm ch12-api-in-practice.zip

Open the folder in VS Code with code rfe-ch12-api-in-practice (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

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

Open in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.

What's inside
  • Directoryrfe-ch12-api-in-practice/
    • Directory.vscode/
      • extensions.json
    • Directorychecks/
      • smoke.robot
    • Directorydemo_app/
      • api.py
      • serve.py
      • store.py
      • web.py
    • Directoryresources/
      • api.resource
    • .gitignore
    • .python-version
    • LAB.md
    • pyproject.toml
    • README.md
    • requirements.txt
    • uv.lock

API checks are fast — a health check answers in a millisecond. That speed is a strategy: run a small, tagged smoke check first, and you learn in a second whether the service is even up before committing to the slow suites.

Close Part 3 with a fast, tagged API health check.

Task 1 — Tag a fast API health check as smoke

Section titled “Task 1 — Tag a fast API health check as smoke”
Edit

Goal: create checks/speed.robot with one smoke-tagged test that GETs the health endpoint and asserts a 200.

Here is the same tagged, fast check against a different endpoint. Adapt it to the health endpoint.

Worked example — adapt it, don’t copy it

*** Settings ***
Library RequestsLibrary
Resource ../resources/api.resource
*** Test Cases ***
Catalog Smoke
[Tags] smoke
${resp}= GET ${API_URL}/api/products
Status Should Be 200 ${resp}

Done when

Api Smoke carries the smoke tag.

Hint 1

Give the test a [Tags] smoke line as its first step so --include smoke selects it.

Hint 2

Hit the health endpoint: GET ${API_URL}/api/health, then Status Should Be 200 ${resp}.

Solution
*** Settings ***
Library RequestsLibrary
Resource ../resources/api.resource
*** Test Cases ***
Api Smoke
[Tags] smoke
${resp}= GET ${API_URL}/api/health
Status Should Be 200 ${resp}
Run

Filter the run to the smoke tag:

Terminal window
uv run robot --include smoke checks
Terminal window
robot --include smoke checks
Terminal window
poetry run robot --include smoke checks

Done when

the API smoke test passes.

Check your understanding

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

  1. A fast API smoke check is valuable because…

    Show the answer

    Answer: it tells you in a second whether the service is up before slower tests run — A one-second API health check fails fast when the service is down — run it before the slow suites.

  2. You run only the smoke tests with…

    Show the answer

    Answer: robot --include smoke — --include smoke selects the smoke-tagged tests.

Key terms

API smokeconcept
A fast, tagged health check — run it first to fail fast when the service is down.

All terms in the glossary →