Skip to content

A data-verification mini-project

Chapter lab: XMLch16-xml.zip · 5 KB

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

Download ch16-xml.zip

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

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

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

Verifying structured output — XML, CSV, JSON — is data verification: parse it, then assert on what it says. The bundled sample_data/results.xml is a junit-style test report. Get Element Attribute reads an attribute off an element; Get Elements gathers every match across the document. Verify the report’s headline numbers.

Task 1 — Verify a junit-style results file

Section titled “Task 1 — Verify a junit-style results file”
Edit

Goal: create checks/results.robot that parses the report, reads its failures attribute, and counts every test case across the suites.

Here is the same attribute-and-count flow over a small inline report. Adapt it to the results file.

Worked example — adapt it, don’t copy it

*** Settings ***
Library XML
*** Test Cases ***
Read A Results Summary
${root}= Parse XML <testsuite failures="2"><testcase/><testcase/><testcase/></testsuite>
${failures}= Get Element Attribute ${root} failures
Should Be Equal As Integers ${failures} 2
${cases}= Get Elements ${root} testcase
Length Should Be ${cases} 3

Done when

the suite defines Test Results Show One Failure.

Hint 1

Parse the file with ${root}= Parse XML sample_data/results.xml, then read its failure count with Get Element Attribute ${root} failures — it is 1.

Hint 2

The cases live one level down, so use a nested path: Get Elements ${root} testsuite/testcase, then Length Should Be ${cases} 6.

Solution
*** Settings ***
Library XML
*** Test Cases ***
Test Results Show One Failure
${root}= Parse XML sample_data/results.xml
${failures}= Get Element Attribute ${root} failures
Should Be Equal As Integers ${failures} 1
${cases}= Get Elements ${root} testsuite/testcase
Length Should Be ${cases} 6
Run

Run:

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

Done when

the report shows one failure across six test cases — Part 5 complete.

Check your understanding

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

  1. Get Element Attribute ${root} failures reads…

    Show the answer

    Answer: the failures attribute of the element — It returns the value of the named attribute on the element.

  2. Verifying a test-results file is an example of…

    Show the answer

    Answer: data verification — asserting on structured output — Parsing and asserting on structured data (XML/CSV/JSON) is data verification.

Key terms

Get Element Attributekeyword
Read an attribute's value from an XML element.
data verificationconcept
Assert on structured output — XML, CSV, JSON — not a UI.

All terms in the glossary →