Cypress setup
3 minute read
This guide will:
- Install Cypress
- Set up e2e testing environments in dev and uat
- Provide other useful information for writing and running tests locally and in pipeline
Ubuntu Users
If you are running Cypress on Ubuntu, you’ll want to have the required dependencies installed on your system.
apt install \
libasound2 libgbm-dev libgconf-2-4 libgtk-3-0 \
libgtk2.0-0 libnotify-dev libnss3 libxss1 \
libxtst6 xauth xvfb
Information
If you want to run Cypress on Ubuntu in WSL in Windows, it’s possible, but it’s not recommended, as there are no benefit in doing so and the performance will be impacted. However, if you’d like to do so, please follow the guide Using Graphical User Interfaces like Cypress’ in WSL2 x-server can be installed via company portal and admin permission will be required for changing the port/type.please refer to Cypress’s official docs for more info about installation.
Prerequisites
Cypress e2e tests repo in gitlab uses yarn for installing Cypress, running tests etc. please do not use npm.
- Install yarn 1.x
docker is not used for running Cypress, dependencies are installed by running yarn install
:
Installing Cypress
- Clone the e2e test repo in gitlab into your Workspace folder:
git clone git@gitlab.com:intellihr/engineering/cypress-e2e-tests.git
- Get into the cloned cypress-e2e-tests folder
cd cypress-e2e-tests
- Run
yarn install
to install dependencies
Set up .env file in dev and uat
-
Get a copy of
.env.uat
and.env.dev
files from 1 password and either copy the content or change the one you need to.env
file. Cypress will only look at the.env
file for its configuration. -
Please update the configcat entry with your own token on the env file Configcat Token
-
Make sure to update the .env file with your own GitLab profile token on the env file Gitlab token
-
If you want to run automated test against code that is still in DEV (not yet pushed to UAT), use the
.env.dev
configuration. -
If you want to run automated test against code that is already in UAT, use the
.env.uat
configuration.
Running Cypress with Docker
- Run
docker compose run --rm local yarn
to install dependencies - Run
docker compose build
to build your local - Run
docker compose run --rm local open
to run cypress with UI Test Runner - On the right corner of Cypress window, make sure Electron browser is selected
- Click on one of the test files on Cypress window, for example,
analytics-high-1.spec.ts
to run the test file
Running Cypress without Docker
- Run
yarn run cy:open-intelliHR
to open Cypress - On the right corner of Cypress window, make sure Electron browser is selected
- Click on one of the test files on Cypress window, for example,
analytics-high-1.spec.ts
to run the test file
Other useful information
Scripts for running Cypress are in package.json file.
All test files are in the “integration” folder and all function files are in the “support” folder.
Other useful information can be found in notion
- How to run Cypress locally
- Automated test guidelines
- Cypress pipeline via Jenkins
- Cypress Tips and Tricks
- How to add new login details for Cypress Jenkins
- Q&A page
Troubleshooting
When run Cypress locally in Windows, if you have the following error
It looks like this is your first time using Cypress: 8.3.1
→ Cypress Version: 8.3.1 Cypress failed to start.
This is usually caused by a missing library or dependency.
The error below should indicate which dependency is missing.
https://on.cypress.io/required-dependencies
Delete the folder of node_modules and re-run yarn install
.
When run Cypress locally in Ubuntu, if you have the following error
[288052:0915/163834.069605:warning:vaapi_wrapper.cc(588)] VAAPI video acceleration not available for swiftshader`
[288052:0915/163834.069804:ERROR:gpu_init.cc(440)] Passthrough is not supported, GL is swiftshader