Upload Cypress 13+ Results
Report Cypress 13 and later results to Currents by uploading Cypress's run results or JUnit reports with currents run upload, from the same or a later CI job
currents run upload reports Cypress 13 and later results to Currents without a Currents package in the Cypress project. Cypress writes its results to files, and currents run upload converts and uploads them, in the same CI job or in a later one. Use it when cypress-cloud does not support your Cypress version (see Compatibility).
There are two formats to upload:
Cypress run results (cypress-json)
JUnit XML (junit --framework cypress)
Attempts
Every attempt of a test
The last attempt only
Flaky tests
A test that passed on a retry is flaky
Never flaky
Screenshots
Each failure screenshot, on its attempt
Added to the reports by a script
Videos
The spec video
None
Use the Cypress run results unless your CI already collects JUnit reports.
Prerequisites
Cypress 13 or later.
@currents/cmd2.3.0 or later and Node.js 20 or later, in the job that uploads.A Currents project ID and record key.
Upload Cypress run results
Save the run results
Add an after:run handler to cypress.config.js. It writes Cypress's run results to a JSON file when the run ends:
const fs = require('fs');
module.exports = {
e2e: {
setupNodeEvents(on) {
on('after:run', (results) => {
fs.mkdirSync('results', { recursive: true });
fs.writeFileSync(
`results/cypress-results-${process.env.CI_NODE_INDEX ?? 1}.json`,
JSON.stringify(results)
);
});
},
},
};The file name includes the machine index, so the files of parallel CI jobs do not overwrite each other. CI_NODE_INDEX is the GitLab CI variable; use the equivalent of your CI provider. The result of cypress.run() has the same format.
Upload the results
Run the command from the Cypress project folder. It reads the screenshots and videos relative to it.
npx @currents/cmd run upload \
--key <record-key> \
--project-id <project-id> \
--input-format cypress-json \
--input-file "results/cypress-results-*.json"--framework is not needed. The Cypress version comes from the file.
npx cypress run exits with an error when a test fails. Upload the results in a step that runs then too, for example in GitLab's after_script or in a GitHub Actions step with if: ${{ !cancelled() }}.
The command prints Run created: and the link to the run. The run shows each spec file with its tests, every attempt, and the screenshots of each failed attempt.
Upload JUnit reports
Configure Cypress's built-in junit reporter to write one report per spec file:
[hash]gives each spec file its own report. Without it, each spec overwrites the report of the previous one.includePending: truekeeps skipped tests in the reports.testsuitesTitleis the group name in Currents.
Delete the reports of earlier runs, then run Cypress. The reporter adds one file per spec file and does not remove old ones, so results/*.xml would also match reports of specs that did not run this time.
Upload the reports with --framework cypress:
The JUnit reports do not refer to the screenshots. To upload them, run attach-screenshots.js from the example before the upload. It adds each failure screenshot to its test as an artifact.
Upload from a later CI job
The Cypress job needs no Currents package, variable or configuration. Keep the result files, screenshots and videos as job artifacts, also when the Cypress job fails (on GitLab, artifacts: when: always; the default saves them only when the job succeeds). Upload them from a later job that runs even when the Cypress job fails. Uploads with the same CI build ID go to the same run, so one upload job can upload the files of several parallel Cypress jobs.
The GitLab CI example runs Cypress on 2 parallel jobs and uploads the results of both from a later job.
Limits
See Limitations of uploaded Cypress 13+ results.
The other options of the command are on currents run upload.
Last updated
Was this helpful?