> For the complete documentation index, see [llms.txt](https://docs.currents.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.currents.dev/getting-started/other-frameworks/cypress/upload-cypress-13-results.md).

# 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`](https://docs.currents.dev/resources/reporters/cypress-cloud.md) does not support your Cypress version (see [Compatibility](https://docs.currents.dev/getting-started/other-frameworks/cypress/integrating-with-cypress/compatibility.md)).

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/cmd` 2.3.0 or later and Node.js 20 or later, in the job that uploads.
* A Currents project ID and [record key](https://docs.currents.dev/guides/record-key.md).

## Upload Cypress run results

{% stepper %}
{% step %}

### 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:

{% code title="cypress.config.js" %}

```javascript
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)
        );
      });
    },
  },
};
```

{% endcode %}

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.
{% endstep %}

{% step %}

### Run Cypress

```bash
npx cypress run
```

{% endstep %}

{% step %}

### Upload the results

Run the command from the Cypress project folder. It reads the screenshots and videos relative to it.

```bash
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() }}`.
{% endstep %}
{% endstepper %}

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:

{% code title="cypress.config.js" %}

```javascript
module.exports = {
  reporter: 'junit',
  reporterOptions: {
    mochaFile: 'results/junit-[hash].xml',
    includePending: true,
    testsuitesTitle: 'e2e',
  },
};
```

{% endcode %}

* `[hash]` gives each spec file its own report. Without it, each spec overwrites the report of the previous one.
* `includePending: true` keeps skipped tests in the reports.
* `testsuitesTitle` is 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.

```bash
rm -rf results
npx cypress run
```

Upload the reports with `--framework cypress`:

```bash
npx @currents/cmd run upload \
  --key <record-key> \
  --project-id <project-id> \
  --input-format junit \
  --input-file "results/*.xml" \
  --framework cypress
```

The JUnit reports do not refer to the screenshots. To upload them, run [`attach-screenshots.js`](https://github.com/currents-dev/currents-examples/blob/main/cypress/gitlab-upload/attach-screenshots.js) from the example before the upload. It adds each failure screenshot to its test as an [artifact](https://docs.currents.dev/resources/reporters/currents-cmd/currents-convert.md#artifacts).

## 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](https://docs.currents.dev/guides/parallelization-guide/ci-build-id.md) go to the same run, so one upload job can upload the files of several parallel Cypress jobs.

The [GitLab CI example](https://github.com/currents-dev/currents-examples/tree/main/cypress/gitlab-upload) runs Cypress on 2 parallel jobs and uploads the results of both from a later job.

{% hint style="warning" %}
Cypress stops before it runs any test, with `We've detected that you're using a 3rd party library that is not supported by Cypress: cypress-cloud`, when its job has `CURRENTS_RECORD_KEY`, `CURRENTS_PROJECT_ID` or `CURRENTS_API_URL` set. GitLab passes project CI/CD variables to every job. Store the record key in a CI/CD variable with another name, for example `CURRENTS_UPLOAD_KEY`, and set `CURRENTS_RECORD_KEY` from it in the upload job only:

```yaml
currents:
  variables:
    CURRENTS_PROJECT_ID: <project-id>
    CURRENTS_RECORD_KEY: $CURRENTS_UPLOAD_KEY
```

Set `CURRENTS_PROJECT_ID`, and `CURRENTS_API_URL` if you use it, in the `variables` of the upload job as above, not as CI/CD variables of the project.

`CURRENTS_UPLOAD_KEY` still reaches every job of the project, the Cypress jobs too. To give it to the upload job only, set an environment scope on the CI/CD variable and the same `environment` on the upload job.

Checked with the `cypress/included` images 14.2.0, 14.5.4 and 16.2.0.
{% endhint %}

## Limits

See [Limitations of uploaded Cypress 13+ results](https://docs.currents.dev/getting-started/other-frameworks/cypress/integrating-with-cypress/compatibility.md#limitations-of-uploaded-cypress-13-results).

The other options of the command are on [currents run upload](https://docs.currents.dev/resources/reporters/currents-cmd/currents-upload.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.currents.dev/getting-started/other-frameworks/cypress/upload-cypress-13-results.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
