How-to

Send a JUnit XML report

Send a JUnit XML report ​

After your tests finish, the pipeline posts one JUnit XML file. ComplexQA stores a run, the suites, the executions, and a test card that stays between runs.

The same import is available by hand: in the project open External tests → Tests and press Load XML. The dialog has the same optional Name field as the request field name. A pipeline uses a key and the request below, not that button.

Prerequisites ​

  • You can open the project and you are an accepted member of its team.
  • You can issue an API key for that team.
  • The test tool can write a JUnit XML file. The root is testsuites or one testsuite.

1. Issue a key ​

A person issues the key in the browser. The pipeline cannot create a key.

  1. Sign in as a member of the team that should receive the report.
  2. Open the profile, tab API keys. From the project, AI → API keys opens the same tab.
  3. Press Create key.
  4. Fill the dialog:
    • Name - how you will recognize the key, for example GitLab build;
    • Team - the team of the project;
    • Lifetime, days - an integer from 1 to 90. A key without a lifetime is not issued.
  5. Press Create key.
  6. Copy the secret at once. ComplexQA does not show it again. The list keeps the name, the team, the lifetime, and the last characters of the secret.

The secret starts with cqa_web_api_. The dialog also shows the header to send:

text
Authorization: Bearer cqa_web_api_…

The key acts as you inside the chosen team. The lifetime is at most 90 days. X-Team-Slug is optional for this key and cannot switch the team. This secret cannot issue or revoke keys.

Do not put the secret in the repository, in the pipeline file, or in a log. Store it in a secret variable. The examples below call it COMPLEXQA_WEB_API_KEY.

To revoke: on the same tab press Revoke. Requests with that secret stop at once.

2. Take the host and the project number ​

The project number is project_id in the address of any page of that project. Example:

text
https://team.example/web/en/junit_xml_test/listing?project_id=50

Here the project number is 50. Store it as COMPLEXQA_PROJECT_ID.

The import address is the same host, path /web_api/junit_xml_test/import:

text
https://team.example/web_api/junit_xml_test/import

Store the host without the path as COMPLEXQA_BASE_URL, for example https://team.example. There is no separate host only for this import.

The project must belong to the key's team. Another team's project is rejected.

3. Write the JUnit XML file ​

The pipeline runs the tests as usual and asks the tool to write JUnit XML. The examples use the file name junit.xml.

PHPUnit:

bash
vendor/bin/phpunit --log-junit junit.xml

pytest:

bash
pytest --junitxml=junit.xml

The root is testsuites or one testsuite. Another root, and XML that cannot be parsed, is not stored. A testcase without name is skipped. The other rows of the file are stored.

Send the file after the tests with an "always" condition, or a failed suite never arrives.

4. Post the file ​

POST /web_api/junit_xml_test/import.

The body is a form, not JSON:

FieldMeaning
project_idproject number from the address
filethe JUnit XML file
nameoptional run name, at most 1000 characters

Run name ​

The run title is not taken from the file. The tool label vitest tests and a PHPUnit suite name stay suite names. They are not the run title.

name sets the title. A useful mask is repository, application version, date. Example: test_site 1.41.1 2026-11-29.

If the field is omitted or only spaces, the list shows the reception date and time as Y-m-d H:i, for example 2026-11-29 10:53. A file that is already stored is not rewritten. The new name and the new totals appear only on the next file.

A name longer than 1000 characters is rejected. api_error.message is Name is too long.

Run totals ​

A Vitest root usually already has tests, failures, errors, and time. A PHPUnit root (testsuites) does not, so without a fill-in the run totals are empty.

When one of those four values is missing on the root, the import counts it from executions that have a name:

Run fieldSource when the root value is missing
testshow many such rows
failuresrows with status FAILED
errorsrows with status ERROR
time_secondssum of time on those rows; if none has a time, the field stays empty

A value the root already sent is not recalculated. Zero stays zero.

Do not add up tests on nested suites. In PHPUnit the parent already includes the child suites, and the sum would count the tests twice. Skipped executions are not a separate column on the run. Status SKIPPED is on the rows and on the charts of the run page.

Send Authorization: Bearer and the secret from step 1. Do not set Content-Type yourself: the client sets it with the form boundary. A session cookie and a CSRF token are not required.

Check from a machine that has the file:

bash
curl --silent --show-error \
  --output response.json \
  --write-out "%{http_code}" \
  --request POST \
  --header "Authorization: Bearer ${COMPLEXQA_WEB_API_KEY}" \
  --form "project_id=${COMPLEXQA_PROJECT_ID}" \
  --form "name=test_site 1.41.1 2026-11-29" \
  --form "file=@junit.xml" \
  "${COMPLEXQA_BASE_URL}/web_api/junit_xml_test/import"

The same request from PowerShell. Use curl.exe: curl without .exe starts another command. Put your application host in COMPLEXQA_BASE_URL.

powershell
curl.exe --silent --show-error `
  --output $env:TEMP\junit-response.json `
  --write-out "%{http_code}" `
  --request POST `
  --header "Authorization: Bearer $env:COMPLEXQA_WEB_API_KEY" `
  --form "project_id=$env:COMPLEXQA_PROJECT_ID" `
  --form "name=test_site 1.41.1 2026-11-29" `
  --form "file=@junit.xml" `
  "$env:COMPLEXQA_BASE_URL/web_api/junit_xml_test/import"
Get-Content $env:TEMP\junit-response.json

Success is HTTP 200 and "api_code":200 in the body. api_result has three fields:

FieldMeaning
junit_xml_run_idnumber of the new run
suite_counthow many suites were stored
testcase_counthow many executions were stored

Example:

json
{
  "api_code": 200,
  "api_result": {
    "junit_xml_run_id": 1,
    "suite_count": 28,
    "testcase_count": 94
  }
}

A rejected file still comes with HTTP 200 and "api_code":-422. Read api_error.message, not only the process exit code of curl.

api_error.messageWhen
Choose a JUnit XML file.no project_id or no file
Project was not found.the project is not in the key's team
JUnit XML is empty.the file is empty
JUnit XML was not accepted.this is not XML, or the root is not testsuites or testsuite
Name is too long.name is longer than 1000 characters

HTTP 401 or 403 means the secret was not accepted: revoked, expired, truncated, or not a cqa_web_api_ key.

Sending the same file again creates a new run and new executions. The test card is not duplicated. In one project the pair classname and name stays one card. The latest class, file, and line are updated on it.

5. Put the post in the pipeline ​

The secret stays in a secret variable. The project number and the host can be ordinary variables.

GitHub Actions, after the test step:

yaml
- name: Send JUnit XML
  if: always()
  env:
    COMPLEXQA_WEB_API_KEY: ${{ secrets.COMPLEXQA_WEB_API_KEY }}
    COMPLEXQA_PROJECT_ID: ${{ vars.COMPLEXQA_PROJECT_ID }}
    COMPLEXQA_BASE_URL: ${{ vars.COMPLEXQA_BASE_URL }}
  run: |
    http_code=$(curl --silent --show-error \
      --output response.json \
      --write-out "%{http_code}" \
      --request POST \
      --header "Authorization: Bearer ${COMPLEXQA_WEB_API_KEY}" \
      --form "project_id=${COMPLEXQA_PROJECT_ID}" \
      --form "name=test_site 1.41.1 2026-11-29" \
      --form "file=@junit.xml" \
      "${COMPLEXQA_BASE_URL}/web_api/junit_xml_test/import")
    cat response.json
    if [ "$http_code" != "200" ] || ! grep -q '"api_code":200' response.json; then
      exit 1
    fi

GitLab CI, a separate job after the tests. Set the variables in the project settings: mask COMPLEXQA_WEB_API_KEY, and set COMPLEXQA_PROJECT_ID and COMPLEXQA_BASE_URL.

yaml
send_junit_xml:
  stage: report
  rules:
    - when: always
  script:
    - |
      http_code=$(curl --silent --show-error \
        --output response.json \
        --write-out "%{http_code}" \
        --request POST \
        --header "Authorization: Bearer ${COMPLEXQA_WEB_API_KEY}" \
        --form "project_id=${COMPLEXQA_PROJECT_ID}" \
        --form "name=test_site 1.41.1 2026-11-29" \
        --form "file=@junit.xml" \
        "${COMPLEXQA_BASE_URL}/web_api/junit_xml_test/import")
      cat response.json
      if [ "$http_code" != "200" ] || ! grep -q '"api_code":200' response.json; then
        exit 1
      fi

The job must be able to read junit.xml. If the tests and the post are different jobs, pass the file as a pipeline artifact.

6. Check in ComplexQA ​

Open the project, group External tests.

  1. Runs - a new row. Its number is junit_xml_run_id.
  2. The run page - two passage charts, Details, and Results with the file rows.
  3. Suites - the suites from this file.
  4. Tests - the cards. The same file again does not add a second card with the same classname and name.
  5. Executions - one row per stored testcase.

On API keys, Last used is filled for that key.

What this call does not do ​

  • It does not start your pipeline from ComplexQA.
  • It does not read the repository and does not store the test code.
  • It does not create a manual test case and does not link an execution to an existing case.
  • It does not write platform autotests (autotest_case, autotest_run, autotest_result) or a manual run (test_run, test_run_result).

Version 1.0.0 · Last updated 2026-11-29

Did this page help?