JUnit XML to Aqua Integration
JUnit XML to Aqua Integration Overview
Purpose Automate the flow from local/unit test execution → JUnit XML generation → ingestion into Aqua as grouped test executions (by Aqua Test Scenario) with pass/fail outcomes, enabling CI/CD visibility and governnce.
High-Level Flow
Developer writes/maintains tests (CodeceptJS / Playwright) using naming conventions embedding Aqua IDs.
Tests run (locally or in GitLab CI) producing a JUnit XML file at output/result.xml.
GitLab CI captures the XML as an artifact and (optionally) a JUnit report.
A publishing stage runs an importer that:
Authenticates against Aqua ( AQUA_URL , AQUA_USER , AQUA_PASSWORD ).
Parses the JUnit XML.
Extracts Aqua Test Scenario IDs (TS…) and Test Case IDs (TC…).
Groups cases by Scenario ID.
Performs one REST API call per Scenario to create executions & results. Exits with appropriate status code so the pipeline can pass/fail.
Test Authoring Conventions
Use IDs inside test suite / test names so they can be parsed:
Scenario (suite/classname/title) prefix:
Test case (individual test) prefix:
TC (e.g., TC1132533 - Load the GitHub homepage )
Regex patterns:
Scenario ID:
/(TS\d+)/
Case ID:
/(TC\d+)/
If an ID is missing, treat that test as invalid (policy: fail import or skip—configurable, recommended fail for data integrity).
Generating JUnit XML (CodeceptJS + mocha-junitreporter)
Typical script (already configured):
npm ci
npx playwright install --with-deps
npm run test # Produces output/result.xml
Ensure codecept.conf.ts
contains a mocha reporter configuration pointing to
output/result.xml (e.g. via mocha-junit-reporter )
.
GitLab CI/CD Pipeline Structure ( .gitlab-ci.yml )
Stages (recommended):
stages:
- test
- upload
Test stage example:
execute_tests:
stage: test
image: node:20
script:
- npm ci
- npx playwright install --with-deps
- npm run test
artifacts:
when: always
expire_in: 1 week
paths:
- output/
reports:
junit: output/result.xml
Upload/import stage example:
upload_to_aqua:
stage: upload
image: mcr.microsoft.com/powershell
dependencies: [execute_tests]
script:
- pwsh ./upload.ps1
(Or use a .NET image / custom importer binary if needed.)
Environment Variables (CI/CD Secrets)
Set in GitLab → Settings → CI/CD → Variables (masked & protected as appropriate):
AQUA_URL
(e.g., https://workshop.aqua-cloud.io/aquaWebNG )
AQUA_USER
AQUA_PASSWORD
Optionally REPORT_FILE (default
./output/result.xm
l )
Importer Responsibilities (Detailed)
For each run:
Read JUnit XML (
REPORT_FILE
).Authenticate: POST token endpoint -> receive bearer token.
Parse
<testsuite>
/<testcase>
nodes.For each
<testcase>:
Extract Scenario ID (look in
classname
or parent suite name text).Extract Case ID (look in
name
).Determine status:
Passed: absence of
<failure>
and<error>
.Failed: presence of
<failure>
or<error>
(capture message + stack if present).
Group test cases by Scenario ID (all with same TS… together).
Build JSON payload per Scenario containing all included case executions.
POST to Aqua Project / Execution endpoint (single call per Scenario).
Track any failed POSTs.
Exit with appropriate code (see below).
Exit Codes (Suggested Mapping)
Code- Meaning
0 —Success (all scenarios posted)
2 — Authentication failure
3 — Network / endpoint unreachable
4 — Partial failure (some scenarios failed)
5 — Invalid or unreadable XML
6 — Missing required IDs / validation error
7 — Unexpected internal exception
CI will fail the job if exit code != 0 (default GitLab behavior), thus potentially failing the pipeline.
JUnit XML Example
<testsuite name="CodeceptJS" tests="2" failures="0">
<testcase classname="TS1132748 - GitHub" name="TC1132533 - Load the GitHub homepage" time="2.131" />
<testcase classname="TS1132748 - GitHub" name="TC1132534 - Load the Google homepage" time="1.842" />
</testsuite>
Troubleshooting
Summary
This setup enforces traceability between automated test execution and Aqua-managed test scenarios/cases by embedding IDs in test names, producing standard JUnit XML, and transforming that into structured Aqua executions inside the CI/CD pipeline, with robust exit codes controlling pipeline outcome.
Last updated
Was this helpful?