Skip to content

Combining file and process checks

Chapter lab: Processesch14-processes.zip · 7 KB

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

Download ch14-processes.zip

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

Terminal window
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch14-processes.zip && unzip -q ch14-processes.zip && rm ch14-processes.zip

Open the folder in VS Code with code rfe-ch14-processes (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-ch14-processes/
    • Directory.vscode/
      • extensions.json
    • Directorychecks/
      • smoke.robot
    • Directorysample_data/
      • app.log
      • catalog.xml
      • orders.csv
      • results.xml
      • settings.cfg
    • Directorytools/
      • inventory.py
    • .gitignore
    • .python-version
    • LAB.md
    • pyproject.toml
    • README.md
    • requirements.txt
    • uv.lock

Real checks combine libraries. Run a process, capture its output to a file with stdout=<path>, then read that file back with OperatingSystem and assert on it. That is the pattern for verifying what a tool produced.

Task 1 — Capture process output to a file and verify it

Section titled “Task 1 — Capture process output to a file and verify it”
Edit

Goal: create checks/combine.robot that runs tools/inventory.py list, captures its stdout to a file under ${OUTPUT_DIR}, then reads that file back and asserts a product name is in it.

Here is the same capture-then-verify flow over a different command. Adapt it.

Worked example — adapt it, don’t copy it

*** Settings ***
Library Process
Library OperatingSystem
*** Test Cases ***
Save Version To A File
${result}= Run Process python3 --version stdout=${OUTPUT_DIR}/version.txt
Should Be Equal As Integers ${result.rc} 0
File Should Exist ${OUTPUT_DIR}/version.txt
${text}= Get File ${OUTPUT_DIR}/version.txt
Should Contain ${text} Python

Done when

the suite defines Capture Inventory To A File.

Hint 1

Add stdout=${OUTPUT_DIR}/inventory.txt as a trailing cell on the Run Process python3 tools/inventory.py list call to capture its output.

Hint 2

After the run, File Should Exist ${OUTPUT_DIR}/inventory.txt, then Get File it and Should Contain ${captured} Travel Mug.

Solution
*** Settings ***
Library Process
Library OperatingSystem
*** Test Cases ***
Capture Inventory To A File
${result}= Run Process python3 tools/inventory.py list stdout=${OUTPUT_DIR}/inventory.txt
Should Be Equal As Integers ${result.rc} 0
File Should Exist ${OUTPUT_DIR}/inventory.txt
${captured}= Get File ${OUTPUT_DIR}/inventory.txt
Should Contain ${captured} Travel Mug
Run

Run:

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

Done when

the CLI output is captured to a file, then read and verified.

Check your understanding

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

  1. How do you send a process's stdout to a file?

    Show the answer

    Answer: Run Process … stdout=path — Run Process takes a stdout=<path> argument that writes the output to a file.

  2. Combining Process and OperatingSystem lets you…

    Show the answer

    Answer: run a tool and then assert on the file it produced — Run a process, capture its output to a file, then read and assert on that file.

Key terms

stdout=<path>concept
Run Process argument that redirects output to a file.

All terms in the glossary →