A data-verification mini-project
Chapter lab: XML
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch16-xml.zip && unzip -q ch16-xml.zip && rm ch16-xml.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch16-xml.zip -OutFile ch16-xml.zip; Expand-Archive ch16-xml.zip -DestinationPath .; Remove-Item ch16-xml.zipOpen 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:
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-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”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} 3Done 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} 6Task 2 — Run it green
Section titled “Task 2 — Run it green”Run:
uv run robot checksrobot checkspoetry run robot checksDone 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.
Get Element Attribute ${root} failuresreads…It returns the value of the named attribute on the element.
Show the answer
Answer: the
failuresattribute of the element — It returns the value of the named attribute on the element.Verifying a test-results file is an example of…
Parsing and asserting on structured data (XML/CSV/JSON) is data verification.
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.