Cypress Web End-to-End Testing
Purpose & When to Use
Run a few critical browser journeys with Cypress on the same gates as playwright-web-e2e. Playwright is the default for a new project; cypress-or-playwright.md decides. Logic belongs in unit tests, service shapes in contract-testing, WCAG checks in accessibility-testing, unstable tests in flaky-test-management. Cypress component testing and Cypress Cloud are out of scope.
Architecture & Design Pattern Mandate
Mandatory companion:
software-engineering-architecture-patterns. Tell the user which patterns you apply and why.
- Plug-in runner behind
verify.d. The project owns how the app starts (E2E_SERVER_COMMAND), when it is ready (/health/ready) and how a user signs in (/login,/api/v1/auth/*,AUTH_REDIRECT_URI,e2e/oidc.sh), and the target isE2E_BASE_URLfor both runners. Cypress only consumes these, so Playwright can replace it, or run beside it during a migration, without a change to the app or CI. - Neutral report as the interface. Cypress writes JUnit;
check-tests.mjsjudges it. - Hermetic tests. Each test creates its own data and runs alone or in any order.
- Considered: Playwright (default); both at once (only during a migration, because two runners cost two sets of upgrades).
Working Rules
These apply to every step below. Full version: agent-working-agreement.
- Look it up. Take versions, flags, API names, config keys and addresses from current official docs or the installed tool's
--help, never from memory. Cannot confirm it? Say so. - Read before writing. Detect the package manager, conventions and existing files first. Never overwrite an existing file without showing the diff.
- Stop for a yes before anything destructive, costly, public, or aimed at a shared or production system. Show the exact command and target first.
- Prove it. Report the command, its exit code and the relevant output. "No tests found" is a failure.
- When a check fails, fix the cause or stop and report. Never skip, delete, weaken or quarantine a test, lower a threshold, or bypass a hook to get a pass.
- Undo only your own changes. Never use
git checkout -- .,git reset --hardorgit cleanas rollback. - Use the shared contract in
engineering-contractfor ports, health paths, env names, auth, errors and file ownership. Readengineering-manifest.jsonfirst if present and record what you did in it. - Apply the principles in
software-engineering-principlesto code you write or review: correct and safe first, then the simplest thing that meets the requirement (KISS, YAGNI), then SOLID and DRY where a concrete cost justifies them.
Topology & Execution Mode
- Standalone (default):
cypress.config.tsandcypress/at the root. Several services or monorepo: in the web app's package or in ane2e/package of its own;scripts/stays at the root. The gate runs every package that has acypress.config.tsand fails if a package has*.cy.tsfiles without one. - Greenfield: full path below. Brownfield: gate beside what exists, then one change at a time.
Handoff Contract
- Consumes: a start command,
/health/ready,/loginand/api/v1/auth/*(identity-provider-auth-contract),scripts/each-package.mjs,scripts/check-tests.mjsandscripts/test-integrity.mjsfromvitest-jest-unit-integration-testing. - Produces:
cypress.config.ts,cypress/**,scripts/cypress-run.mjs,scripts/merge-junit.mjs,scripts/verify.d/75-e2e-cypress.sh,reports/e2e-cypress.xml. - Next Recommended Skills:
github-actions-ci-cd,accessibility-testing,flaky-test-management.
Prerequisites & Latest-Version Check
npm view cypress version engines; checked 2026-11-29: 16.4.0, Node^22 || ^24 || >=26. Works with TypeScript 6.0.3 and 7.0.2.- Chrome on the machine (GitHub's Ubuntu runners have it), or a
cypress/included:<version>image, which exists for amd64 and arm64. About 530 MB for the binary on macOS. Docker fore2e/oidc.sh. - Set both before the first install:
CYPRESS_CRASH_REPORTS=0(no exception reports) andCYPRESS_COMMERCIAL_RECOMMENDATIONS=0(no Cloud promotion in logs).
Inputs to Confirm
- Cypress or Playwright, by the reference. Journeys that must work, written down before the specs.
- Browser: Chrome by default. Electron is deprecated; WebKit is experimental and has no
cy.origin(), so the sign-in here cannot run on it. - Target: local app (default) or a deployed URL. Only
*.smoke.cy.tsspecs run against a shared or production URL. - Sign-in method; for an external target a dedicated test user, never a real person's account.
Step-by-Step Procedure
Greenfield Path
- Apply the decision rule and record it:
manifest.mjs record decision web-e2e-runner --title "Cypress for web end-to-end tests" --status accepted --alternatives "Playwright"(engineering-contract). - Export the two variables above. Install
cypressas an exact dev dependency, plustypescriptand@types/nodeif missing.--ignore-scriptsskips the binary, and pnpm 11 stops withERR_PNPM_IGNORED_BUILDSuntilpnpm-workspace.yamlsaysallowBuilds: { cypress: false }(ortrue). Then runnpx --no-install cypress installandnpx --no-install cypress verify. - Copy cypress.config.ts and assets/cypress/ (
tsconfig.json,support/, the smoke spec) and replace the heading placeholder. Its owntsconfig.jsonkeeps Cypress globals apart from Vitest's or Jest's; excludecypress/from the app's. Addcypress.config.tsto the roottsconfig.jsoninclude, or ESLint's project service does not find it. Addcypress/screenshots,cypress/videos,cypress/downloadsandreports/to.gitignore. - Sign-in: copy oidc.sh to
e2e/unless it is already there. It is the same file as inplaywright-web-e2e: a pinned Keycloak on loopback port 3018 with exactly this run's user; it refuses anyAPP_ENVbutlocal/test. Stop it withAPP_ENV=test bash e2e/oidc.sh down.cy.signIn()then usescy.session(setup through/loginand the provider's own form incy.origin, validation by/api/v1/auth/me, reused across specs). Auth module on another origin than the app (single-page app and gateway): setAUTH_REDIRECT_URI(engineering-contract) to its callback, same host name as the app, for examplehttp://127.0.0.1:4000/api/v1/auth/callback;oidc.shandsignInfollow it, as Playwright does.E2E_SERVER_COMMANDstarts both withCORS_ALLOWED_ORIGINSset to the app. Run with one and with two loopback origins against Keycloak; two host names are not verified. An app without sign-in: leave outoidc.sh,commands.tsand its import. - Copy cypress-run.mjs and merge-junit.mjs to
scripts/, 75-e2e-cypress.sh toscripts/verify.d/, and the gates if missing (vitest-jest-unit-integration-testingsteps 3 and 4, witheach-package.mjs). Cypress has nowebServeroption;cypress-run.mjsstarts the app throughoidc.sh, waits for/health/ready(E2E_READY_PATHnames another path; an HTML page, such as a single-page fallback, is not readiness), runs Chrome, joins the reports and stops only what it started. Several processes or migrations: put them into a script and setE2E_SERVER_COMMAND="bash <script>". - Write each journey test-first in
cypress/e2e/<journey>.cy.ts:cy.signIn(), thency.visit(). Select by role or label text (cy.contains('button', 'Save'),cy.contains('label', 'Name')) ordata-testid; no CSS chains, no XPath. Assert with.should(), nevercy.wait(<number>). Every test needs an assertion on the result. - Record the count:
node scripts/check-tests.mjs --suite e2e-cypress --junit reports/e2e-cypress.xml --write, then commitquality-baseline.json.
Brownfield Path
- Discover (read-only):
git ls-files | grep -iE 'cypress|\.cy\.[jt]sx?$|playwright' | head -50 git grep -nE 'cy\.wait\([0-9]|\.(only|skip)\(|Cypress\.env\(|cy\.(exec|end|prompt)\(|retries|force: *true|specPattern' -- '*.ts' '*.tsx' '*.js' git grep -nE -e '--record|CYPRESS_RECORD_KEY|--pass-with-no-tests|cypress-io/github-action' -- .github package.json '*.yml' node -p "require('cypress/package.json').version" - Run the existing suite twice; record passes, failures and duration. Hide nothing.
- Report: version gap, removed calls in use (
Cypress.env(),cy.exec(),cy.end()are gone in 16), Cypress Cloud use with its cost and what it uploads, specs without assertions,retriesabove 0. Show the plan and wait. - Add the gate beside what exists: the JUnit reporter lines of cypress.config.ts with
includePending: true, itsexcludeSpecPatternfor quarantined specs, the two scripts,75-e2e-cypress.sh, and a baseline at today's count. The baseline needs a run without failed or pending tests: until then keep75-e2e-cypress.shout and follow brownfield step 4 ofvitest-jest-unit-integration-testing. Cypress 13 works (run on 13.17.0):cypress-run.mjsleaves out--posix-exit-codeswherecypress run --helpdoes not list it. Leave spec names and an existing sign-in alone. The gate looks forcypress.config.tsand*.cy.ts; a JavaScript project changes these two names in its copy. - Set
retries: 0. A test that now fails was already unstable: fix it or useflaky-test-management. - Upgrade one major at a time with the changelog; each needs a yes. Secrets move from
Cypress.env()tocy.env(), public values toexpose.
Everyday Work
- A UI change breaks a test: fix the selector if the element moved; change an assertion only if the requirement changed, and say which.
- Debug a failure:
cypress/screenshots/, or against a running appE2E_BASE_URL=http://127.0.0.1:3000 npx cypress open. There is no trace viewer without Cloud. - Debug a flaky spec: repeat it on its own, 10 times, with
node scripts/cypress-run.mjs --spec cypress/e2e/<name>.cy.ts. A temporaryretries: { experimentalStrategy: 'detect-flake-but-always-fail', experimentalOptions: { maxRetries: 2, stopIfAnyPassed: true }, openMode: false, runMode: true }shows whether a retry passes and still fails the run (checked on 16.4.0). Plainretries: 1anddetect-flake-and-pass-on-thresholdturn a flaky test green: do not use them. - Quarantined specs are named
*.quarantined.cy.ts; onlyE2E_QUARANTINED=1 node scripts/cypress-run.mjsruns them; the gate ignores that variable. - Smoke after a deploy:
E2E_BASE_URL=https://… node scripts/cypress-run.mjsruns the smoke specs only. cypress-run.mjsaccepts--spec,--browserand a few display flags, and hidesCYPRESS_*variables from Cypress. Other settings go intocypress.config.ts, where they are reviewed.
Approval Stops
Wait for a yes before: any other spec against a shared or production URL, Cypress Cloud, --record or cy.prompt (name the cost and that data leaves the project), a major upgrade, quarantining or removing a test, lowering the baseline, moving to another runner.
Owned Files & Environment Contract
- Owned:
cypress.config.ts,cypress/**,scripts/cypress-run.mjs,scripts/merge-junit.mjs,scripts/verify.d/75-e2e-cypress.sh.e2e/oidc.shis shared withplaywright-web-e2e; whichever skill came first owns it, and both ship the same file. .env.exampleblock:E2E_BASE_URL=(CYPRESS_BASE_URLstill works; both set to different values is refused),E2E_TEST_USER_EMAIL=,E2E_TEST_USER_PASSWORD=(both only for an external target, otherwise generated),E2E_SERVER_COMMAND=(defaultnode --run start),E2E_READY_PATH=(default/health/ready). Optional foroidc.sh:E2E_OIDC_PORT,E2E_OIDC_NAME,E2E_OIDC_AUDIENCE,E2E_OIDC_ROLES,E2E_OIDC_TENANT. Keep one entry per name ifplaywright-web-e2eadded it.- Secrets: never in
cypress.config.ts,expose,cypress.env.jsonor a command line. Read them withcy.env(), type them with{ log: false }. A failedcy.request()prints its headers, session cookies included, into the report: usefailOnStatusCode: falseand assert the status. Screenshots can show personal data; keep CI artifacts private and short-lived.
Verification & Smoke Tests
npx tsc --noEmit -p cypress
node scripts/test-integrity.mjs # exit 1 after adding it.only to a .cy.ts file
bash scripts/verify.d/75-e2e-cypress.sh # exit 0 and a line "OK e2e-cypress: ..."
node scripts/cypress-run.mjs --spec 'cypress/e2e/**/*.smoke.cy.ts' # exit 0
node scripts/cypress-run.mjs --spec 'cypress/e2e/**/*.none.cy.ts' # exit 1, "no spec files were found"
After changing a script, run its tests from the skill folder: node --test scripts/merge-junit.test.mjs scripts/cypress-run.test.mjs.
Break things on purpose and show each failure, then undo: rename the page heading (smoke spec fails); delete one spec (below the baseline); it.skip (skipped test); exit the app during the run (the app exited during the run, no process left).
Common Failure Modes & Rollback
Cypress binary is missing: the package manager skipped the install script.npx --no-install cypress install, thenverify.- Exit code 5 read as "unknown error": without
--posix-exit-codesthe code is the number of failed tests. - Only the last spec is in the report:
mochaFilehas no[hash]; each spec overwrote the one before. is not well-formed XMLorreports failures=... but shows ...: the reporter was cut off or another tool wrote intoreports/cypress. Do not edit the report; rerun.- Skipped tests are not reported:
includePendingis missing.merge-junit.mjsstill adds them from the totals. Electron ... deprecatedin the output: no browser was named. Usecypress-run.mjsor--browser chrome.Cypress.env() ... removed: usecy.env().- Error about a different origin during sign-in: the provider's page is handled outside
cy.origin(). Only functions defined inside its callback can be used there. - Sign-in stops at the provider's form: its labels differ; change them in
commands.ts.invalid redirect_uri: the app's address is nothttp://127.0.0.1:$PORT; setPUBLIC_BASE_URL; or the callback is on another origin, setAUTH_REDIRECT_URI. not ready after ... s: readreports/e2e-cypress-server.log;/health/readyis not 200, or answers with an HTML page.is not acceptedornot passed to Cypress: put the setting intocypress.config.ts.port ... is already in use: stop that app or setPORT. A running app does not know this run's user.- Parallel runs on one Linux machine fail to start: they can collide on one Xvfb display. Start one Xvfb and set
DISPLAYfor all, or run one after the other. - Rollback: revert the owned paths from the restore point; remove the dev dependency and
APP_ENV=test bash e2e/oidc.sh down. Leavee2e/oidc.shif Playwright uses it. A flaky test stays blocking until fixed, or quarantined with approval.