- Cypress Docker images for dependencies
- Installing and caching Cypress itself
- How to start server and run Cypress tests
- CircleCI Orb example
- GitHub Actions example
- GitHub reusable workflows
- How to run tests faster
- Cypress paid Test Replay
- ❤️ GitHub Actions
- 👏 CircleCI
- 👍 Jenkins
- 🎉 Something else
- sign up for free account on CircleCI
- use your fork of https://github.com/bahmutov/testing-app-example
Or make your copy of it using
$ npx degit https://github.com/bahmutov/testing-app-example test-app-my-example
$ cd test-app-my-example
$ npm i
$ npm start
# create GitHub repo and push "test-app-my-example"
- run the specs in the interactive mode with
cypress open
- run the specs in the headless mode with
cypress run
See https://on.cypress.io/command-line
+++
$ npm i -D cypress
$ npx @bahmutov/cly init -b
# add a test or two
- sign up for CircleCI
- add your project to CircleCI
+++
- install and cache dependencies
- start
todomvc
server in the background - run Cypress using
npx cypress run
- (maybe) stop the
todomvc
server
+++
version: 2
jobs:
build:
docker:
- image: cypress/base:16.14.2-slim
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- dependencies-
- run:
name: Install dependencies
# https://docs.npmjs.com/cli/ci
command: npm ci
- save_cache:
paths:
- ~/.npm
- ~/.cache
key: dependencies-{{ checksum "package.json" }}
# continued: start the app and run the tests
+++
# two commands: start server, run tests
- run:
name: Start TodoMVC server
command: npm start
working_directory: todomvc
background: true
- run:
name: Run Cypress tests
command: npx cypress run
+++
Alternative: use start-server-and-test
- run:
name: Start and test
command: npm run ci
{
"scripts": {
"start": "npm start --prefix todomvc -- --quiet",
"test": "cypress run",
"ci": "start-test http://localhost:3000"
}
}
A much simpler CI configuration.
version: 2.1
orbs:
# import Cypress orb by specifying an exact version x.y.z
# or the latest version 2.x.x using "@1" syntax
# https://github.com/cypress-io/circleci-orb
cypress: cypress-io/cypress@2
workflows:
build:
jobs:
# "cypress" is the name of the imported orb
# "run" is the name of the job defined in Cypress orb
- cypress/run:
start: npm start
See https://github.com/cypress-io/circleci-orb
+++
Look how tests are run in .circleci/config.yml using cypress-io/circleci-orb.
version: 2.1
orbs:
# https://github.com/cypress-io/circleci-orb
cypress: cypress-io/cypress@2
workflows:
build:
jobs:
- cypress/run:
# store videos and any screenshots after tests
store_artifacts: true
+++
version: 2.1
orbs:
# https://github.com/cypress-io/circleci-orb
cypress: cypress-io/cypress@2
workflows:
build:
jobs:
# set CYPRESS_RECORD_KEY as CircleCI
# environment variable
- cypress/run:
record: true
https://on.cypress.io/dashboard-introduction
+++
version: 2.1
orbs:
# https://github.com/cypress-io/circleci-orb
cypress: cypress-io/cypress@2
workflows:
build:
jobs:
- cypress/install # single install job
- cypress/run: # 4 test jobs
requires:
- cypress/install
record: true # record results on Cypress Dashboard
parallel: true # split all specs across machines
parallelism: 4 # use 4 CircleCI machines
+++
Never struggle with CI config 👍
- github.com/cypress-io/circleci-orb
- circleci.com/orbs/registry/orb/cypress-io/cypress
- 📺 CircleCI + Cypress webinar
- cross-platform CI built on top of Azure CI + MacStadium
- Linux, Windows, and Mac
- Official cypress-io/github-action
+++
jobs:
cypress-run:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
# https://github.com/cypress-io/github-action
- uses: cypress-io/github-action@v6
with:
start: npm start
wait-on: 'http://localhost:3000'
Check .github/workflows/ci.yml
name: ci
on: [push]
jobs:
test:
# use the reusable workflow to check out the code, install dependencies
# and run the Cypress tests
# https://github.com/bahmutov/cypress-workflows
uses: bahmutov/cypress-workflows/.github/workflows/standard.yml@v1
with:
start: npm start
https://github.com/bahmutov/cypress-workflows
- use
npm ci
command instead ofnpm install
- cache
~/.npm
and~/.cache
folders - use start-server-and-test for simplicity
- store videos and screenshots yourself or use Cypress Dashboard
- Run changed specs first
- Run tests by tag
- Run tests in parallel
- Run specs based on test IDs in the modified source files
+++
- Run changed specs first
📝 Read Get Faster Feedback From Your Cypress Tests Running On CircleCI
$ specs=$(npx find-cypress-specs --branch main)
$ npx cypress run --spec $specs
+++
- Run tests by tag
📝 Read How To Tag And Run End-to-End Tests
it('logs in', { tags: 'user' }, () => ...)
$ npx cypress run --env grepTags=user
+++
- Run tests in parallel
+++
- Run specs based on test IDs in the modified source files
📝 Read Using Test Ids To Pick Cypress Specs To Run
+++
- 📝 Make Cypress Run Faster by Splitting Specs
- 📝 Split Long GitHub Action Workflow Into Parallel Cypress Jobs
- 📝 Testing Time Zones in Parallel
- 🔌 plugin cypress-split
- 📝 read https://glebbahmutov.com/blog/cypress-parallel-free/
- optional paid Cypress service for recording tests
- requires Cypress v13+
- recreates the local time travel experience
+++
Click on the Cypress Cloud badge to view recorded tests
+++
Test replays for each test run at https://cloud.cypress.io/projects/89mmxs/runs
Good example test is "can mark an item as completed" from 02-adding-items/answer.js
+++
+++
Find the CI you use on https://on.cypress.io/continuous-integration and https://github.com/cypress-io/cypress-example-kitchensink#ci-status
- presentation CircleCI Orbs vs GitHub Actions vs Netlify Build Plugins CI Setup
- my GitHub Actions blog posts
- my CircleCI blog posts
➡️ Pick the next section or jump to the 08-retry-ability chapter