Earlier I wrote a
blog post about how easy it is to integrate and run cypress within your CI environment. Quick. Easy. Quite painless.
Here are but a few examples!
Gitlab
# ./.gitlab-ci.yml
image: cypress/base:10
cypress-e2e:
script:
- npm install
- $(npm bin)/cypress run
Circle CI
# ./circle.yml
- run:
name: Running E2E tests
command: cypress run --reporter junit --reporter-options "mochaFile=results/my-test-output.xml"
- store_test_results:
path: results
Docker
#!/usr/bin/env bash
# ./cy-run.sh
# explanation of the "docker run" command line arguments
#
# -it = interactive terminal
# -v $PWD:/e2e = map current folder to /e2e inside the container
# -w /e2e = set working directy to /e2e
# $@ = pass any arguments to this script to the Cypress command
# like "./cy-run.sh --record"
#
# Docker image "cypress/included:3.2.0" has its entrypoint
# set to "cypress run" by default
docker run -it -v $PWD:/e2e -w /e2e cypress/included:6.2.1 $@
Want to build custom Test Images beforehand? Create a Docker file!
FROM cypress/base:10
WORKDIR /app
# Copy our test page and test files
COPY index.html ./
COPY cypress.json ./
COPY package.json ./
COPY cypress ./cypress
# Install npm dependencies, can also use "npm ci"
RUN npm install
For more information, checkout the official Cypress
article on using Docker!
Advanced Gitlab
Here at Aspera, we utilize Gitlab for our day-to-day builds and test automation. There are so many options when it comes to configuring your CI to run tests the way you want. With cypress images built so reliably, you can focus on building up your automation setup. Here's a partial example of how you can utilize the power of Gitlab CI to run tests the way you want.
.cypress_example_template:
image:
name: cypress/included:4.9.0
# cypress/included images have entrypoint set to "cypress"
# which conflicts with GitLab CI wrapper shell script
entrypoint: [""]
before_script:
- export CYPRESS_CI_JOB_ID=$CI_JOB_ID
- npm install
variables:
SLACK_WEBHOOK_URL: https://slack.com/webhookurl/123
CYPRESS_CACHE_FOLDER: ${CI_PROJECT_DIR}/.cypress
CYPRESS_RETRIES: 2
CYPRESS_TEST_ENV: 'qa'
retry: 0
allow_failure: true
artifacts:
when: always
paths:
- mochawesome-report/
- cypress/screenshots
- cypress/videos
expire_in: 3 days
only:
refs:
- master
test:cypress-example:
extends: .cypress_template
stage:test-phase-1
script:
- npm run cypress:run
#Aspera#ci#cypress#gitlabci#whatsnew