docker compose
. For automated frontend tests, we'd like to setup Cypress. Locally, we develop inside Windows Subsystem for Linux (WSL2, Ubuntu).cypress open
command offers a nice interactive GUI that offers a live view of what's going on in the tests any many other nice features we don't want to miss out.cypress-on-rails
)I've asked this question directly to the Cypress team and Mike had a great answer here.
It turns out that WSL now ships with all batteries included to forward Linux GUI apps to Windows, that is, no manual installation of an X11 server is necessary anymore. This project is called WSLg. If you already use WSL, just do wsl --update
and you will automatically get the new version.
With this, the Docker compose setup from here works flawlessly. While the original question was about having the Cypress interactive GUI run on Windows directly and then somehow let it connect to the Docker container to have it execute the tests there, this solution (where the GUI runs within the Docker container but is forwarded to Windows) works great now and does not involve any additional setup.
Here's the minimal Docker compose setup:
# Instructions for interactive mode
# https://www.cypress.io/blog/2019/05/02/run-cypress-with-a-single-docker-command#Interactive-mode
services:
cypress:
# https://on.cypress.io/command-line#cypress-open
entrypoint: cypress open --project ./your/folder/name/
environment:
# for X11/Wayland in WSLg
- DISPLAY
volumes:
# for Cypress to communicate with the X11 server pass this socket file
# in addition to any other mapped volumes
- /tmp/.X11-unix:/tmp/.X11-unix