Upload from CI
Cypress
Upload Cypress screenshots to CirCI with @circi/cypress. Keep cy.screenshot(); each image is cropped to the element or page, and the run uploads when it ends.
@circi/cypress uploads the screenshots your Cypress tests take to your CirCI server, which compares each one with its baseline and asks your team to review what changed. Your tests keep Cypress's own cy.screenshot('name'); the plugin crops each screenshot to the element or the page's content, and cypress run uploads them when it ends.
Set it up
Section titled “Set it up”-
Install the plugin:
Terminal window npm install --save-dev @circi/cypress -
Add it to the Cypress config:
cypress.config.ts import { circi } from '@circi/cypress'import { defineConfig } from 'cypress'export default defineConfig({e2e: {setupNodeEvents: circi({ name: 'cypress' }),},})If you already have a
setupNodeEvents, call the plugin inside it:circi({ name: 'cypress' })(on, config), then returnconfig. -
Import its support file in
cypress/support/e2e.ts(andcomponent.tsfor component tests):cypress/support/e2e.ts import '@circi/cypress/support' -
Take named screenshots in your specs:
cypress/e2e/home.cy.ts it('looks right', () => {cy.visit('/')cy.screenshot('home')cy.get('header').screenshot('header')}) -
In CI, with the project's token as
CIRCI_TOKENand your CirCI address asCIRCI_API_URL(Create a project), runnpx cypress run. The upload happens when the run ends. Without the token or the address the plugin prints[circi] skipped: set CIRCI_API_URL and CIRCI_TOKEN to upload screenshotsand the run is unaffected. -
Open the build in the dashboard. The first build has nothing to compare with, so approve every screenshot once (First review).
Screenshots are named by the spec's path from the project root, then the name you pass: cypress/e2e/home.cy.ts/home and cypress/e2e/home.cy.ts/header, the way the Vitest plugin names its own. Two specs with the same file name in different folders don't collide. Always pass a name, and note that moving or renaming a spec file starts new baselines. A name with nothing usable in it (only punctuation or non-Latin characters, such as '!!') is skipped with a [circi] skipped screenshot line, and the test is unaffected. Add .circi to .gitignore.
What is uploaded
Section titled “What is uploaded”Every screenshot a cypress run takes with a name, from that run only: the plugin's folder, .circi/screenshots/cypress, is emptied when the run starts. The other CirCI plugins have their own folders next to it (vitest, storybook), which Cypress never touches or uploads. Cypress's automatic screenshot of a failing test isn't uploaded, and neither is a cy.screenshot() without a name. cypress open uploads nothing.
What a screenshot shows
Section titled “What a screenshot shows”The support file keeps cy.screenshot()'s signature and what it yields, and changes what it captures so a screenshot holds the thing and nothing around it:
- An element (
cy.get(sel).screenshot('x')): its own box, cropped tight. - The page (
cy.screenshot('x')): the page's content, as tall as the content. A short page isn't padded to the viewport's height, and Cypress's own interface isn't in it. - Component testing: the mounted component's box, not the viewport.
- A hidden element, or one with no size, is an error (
nothing to capture), not a blank image. paddingadds space on purpose:cy.get(sel).screenshot('x', { padding: 10 }). An explicitcaptureorclipis left as you wrote it.
Before it captures it waits for fonts and stops animations, transitions and the caret. The image's size follows the display's pixel ratio, so take the screenshots on the same machine image every time, which in practice means CI.
Options
Section titled “Options”The same names and meanings as the Vitest plugin:
| Option | Default | What it does |
|---|---|---|
name |
cypress |
Build name. Give each browser or suite its own (cypress-chrome). |
wait |
false |
Wait for the result and fail the run while changes need review and this job is the gate. |
strict |
false |
Also fail the run if the upload fails. By default the tests pass or fail on their own. |
shard |
CIRCI_SHARD (2/4) |
This machine's share of a parallel run: give every machine the same name and its own shard, and they become one build. |
dir |
.circi/screenshots |
The folder the plugins share, under the project root; this plugin writes to its cypress folder. |
clean |
true |
Empty the plugin's own folder when the run starts. |
root |
Cypress's project root | The project root. |
apiUrl, token |
CIRCI_API_URL, CIRCI_TOKEN |
Where to upload, and the project's token. Keep the token in the environment. |
Cypress keeps one handler per event, so your own before:run, after:screenshot or after:run handler replaces the plugin's (or the other way round); a helper such as cypress-on-fix lets both run. The complete CI workflow, with the pull request check, is in the GitHub Actions guide: replace its test and upload steps with npx cypress run.
Coming from @argos-ci/cypress
Section titled “Coming from @argos-ci/cypress”CirCI doesn't accept uploads from the Argos SDKs. Replace cy.argosScreenshot() with cy.screenshot() and add the plugin above: it uploads what Cypress writes, so there's no separate upload step.