← Back: Documentation Overview
This document outlines the steps for setting up Cypress in your project. Cypress is an end-to-end testing framework designed to make it easy to write and run tests for web applications. This guide will cover how to set up Cypress both in a Docker container and locally on your machine.
Cypress is a powerful, open-source testing framework for web applications that enables developers to write tests with a simple, easy-to-understand syntax. It automatically handles the complexity of dealing with asynchronous code, making it easier to write and maintain reliable tests.
With Cypress, you can test your application by simulating real user interactions and verifying that your application behaves as expected under various conditions. You can learn more about Cypress on the official website .
To run your Cypress tests in a Docker container, follow these steps:
- Run the Docker Compose command to start the test environment:
docker-compose up --profile tests
- Create a
.docker.env
file in the root of your project, if it does not exist, and configure the necessary environment variables. The file must include at least the following variables:
# .frontend/.env.docker
VITE_BACKEND_DOMAIN=http://localhost:8000
VITE_CYPRESS_BACKEND_DOMAIN=http://backend:8000
To set up Cypress and run tests locally, follow these steps:
- Install the necessary dependencies by running the following command in ./frontend:
yarn install
- Navigate to the
frontend
folder and run the Cypress tests using the following command:
yarn run cypress run
- Create a
.env.local
file in thefrontend
folder, if it does not exist, and configure the necessary environment variables. The file must include at least the following variables
# frontend/.env.local
VITE_BACKEND_DOMAIN=http://localhost:8000
VITE_CYPRESS_BACKEND_DOMAIN=http://localhost:8000
With these steps, you should now be able to successfully set up and run Cypress tests both in Docker and locally on your machine.
The Docker Compose configuration sets up a Cypress service for running end-to-end tests in a multi-container environment. Below is a short explanation of each configuration option in the file.
cypress:
depends_on:
- frontend
- backend
profiles:
- tests
build:
context: ./frontend
dockerfile: Dockerfile.cypress
platform: linux/arm64/v8
env_file:
- ./frontend/.env.docker
environment:
- IS_DOCKER=YES
- CYPRESS_baseUrl=http://frontend:3000
volumes:
- ./frontend/cypress:/frontend/cypress
command: "yarn run cypress:run"
depends_on
: Specifies that thecypress
service depends on thefrontend
andbackend
services. This ensures that thefrontend
andbackend
containers are up and running before thecypress
service starts.profiles
: Assigns thetests
profile to thecypress
service. This allows you to selectively start thecypress
service using the--profile
option withdocker compose
.build
: Defines the build context and Dockerfile for thecypress
service. The build context is set to the./frontend
directory, and the Dockerfile is namedDockerfile.cypress
.platform
: Specifies the target platform for thecypress
service, which is set tolinux/arm64/v8
in this case.env_file
: Loads environment variables from the specified file./frontend/.env.docker
. This file contains the environment settings needed for thefrontend
service.environment
: Defines additional environment variables for thecypress
service.IS_DOCKER=YES
is used to indicate that the service is running inside a Docker container, andCYPRESS_baseUrl
is set to the URL of thefrontend
service.volumes
: Creates a volume mapping between the./frontend/cypress
folder on the host machine and the/frontend/cypress
folder inside the container. This allows the Cypress tests to be stored and accessed in the container.command
: Specifies the command to run when thecypress
service starts, which isyarn run cypress:run
in this case. This command will execute the Cypress tests within the container.