tyler36 / ddev-cypress

Cypress E2E testing for use with DDEV
Apache License 2.0
11 stars 7 forks source link

Unable to run Cypress in DDEV #26

Closed martyspain closed 7 months ago

martyspain commented 1 year ago

I'm unable to get Cypress to run using ddev cypress-open - I get the following error every time:

Cypress failed to start.

This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies

Please refer to the error below for more details.

----------

Command was killed with SIGTRAP (Debugger breakpoint): /root/.cache/Cypress/12.6.0/Cypress/Cypress --no-sandbox --smoke-test --ping=381

----------

Platform: linux-x64 (Debian - 11.6)
Cypress Version: 12.6.0
Failed to run cypress-open : exit status 1

Any help or pointers as to what I'm missing or doing wrong would be gratefully received!

tyler36 commented 1 year ago

Hi @martyspain and thanks for the issue report.

That particular error is frustrating and I haven't figured out exactly what causes it. I have PR #23 which is designed to bump the Cypress version but when I tried the latest, 12.13.0 I got the same error in the tests.

I run manualy tests locally on Windows 10, WSL Ubuntu and on PRs with Github actions. Some of the docker builds seem flaky and will work locally but not in Github actions; occasionally, even the other way around. Since the only thing changing is their image I'm not sure there is anything I can do.

Fix?

image: cypress/included:12.6.0

You can find a list of support tags here.

codemonkey1988 commented 1 year ago

Hi,

first of all, thanks for sharing your configuration. It helped me getting started implementing cypress into my ddev dev env.

When trying to run the tests on another machine, I ran into the same error as described. After some time of debugging, I realized that the host machines user has uid=998. This uid is used to run the cypress command inside the container. But cypress required the node user (uid=1000) in order to work. So that was the reason why I got this error message. Setting user: "1000:1000" in the docker-compose.cypress.yaml made the command running again. But using this, I ran into permission problems with generated videos and screenshots of course.

Maybe this helps someone who is dealing with the same problem.

tyler36 commented 1 year ago

@codemonkey1988 Thanks for sharing your findings. Any ideas on what we can change to address this?

codemonkey1988 commented 1 year ago

@tyler36 Sorry for answering this late.

I looked into the cypress docker images and found this https://github.com/cypress-io/cypress-docker-images/tree/master/examples/included-as-non-root-mapped

I'm not that deep into ddev yet but maybe ddev can run the steps described. For web_images, itt is possible to customize the image. Maybe it's possible for additional services to provide a Dockerfile that create a new user with host system user ID.

tyler36 commented 1 year ago

@codemonkey1988

Thanks for the link.

The docker-compose.cypress.yaml already include a line that maps the host UID to the non-root UID in the container.

user: "${DDEV_UID}:${DDEV_GID}"

IIRC, there was a release where this was dropped, but it caused permission issues when trying to remove screenschots and videos created from failed tests from the host.

It should be fixed in the latest version. Just run ddev get tyler36/ddev-cypress to update/reinstall.

ultimike commented 1 year ago

I am also unable to get Cypress running using this add-on. My setup:

Here are the commands I ran in my attempt:

  1. ddev get tyler36/ddev-cypress
  2. ddev restart
  3. ddev cypress-open

The last command resulted in an error:

Cypress verification timed out.

This command failed with the following output:

/root/.cache/Cypress/12.6.0/Cypress/Cypress --no-sandbox --smoke-test --ping=225

----------

Command timed out after 30000 milliseconds: /root/.cache/Cypress/12.6.0/Cypress/Cypress --no-sandbox --smoke-test --ping=225
Timed out

----------

Platform: linux-arm64 (Debian - 11.6)
Cypress Version: 12.6.0
Failed to run cypress-open : exit status 1

I ran the ddev cypress-open command several times - same error each time as above.

Any suggestions?

-mike

rfay commented 1 year ago

Why are you using an ancient version of Colima @ultimike ? I don't think it should matter, but it doesn't seem like a good idea.

ultimike commented 1 year ago

@rfay Heh - ever since I got burned with that one Colima update, I haven't updated since then. 0.5.1 isn't that old. 0.5.5 is the latest, so 0.5.1 is only 6 months old.

Would you recommend updating Colima whenever DDEV is updated?

rfay commented 1 year ago

Again, I would be very surprised if Colima version is your problem here, and I understand about your worries. I sometimes delete my colima profile when upgrading. I guess my suggestion would be to upgrade Colima a month or so after the new version comes out :)

ultimike commented 1 year ago

By your "colima profile", you mean the entire ~/.colima directory? Then after upgrading, I'll need to do a colima start --cpu 4 --memory 6 --disk 100 --vm-type=qemu --mount-type=sshfs --dns=1.1.1.1 again (from here), correct?

rfay commented 1 year ago

We're kind of off-topic here, but I recommend colima delete and then colima start --cpu 4 --memory 6 --disk 100 --vm-type=qemu --mount-type=sshfs --dns=1.1.1.1

I often test by using a separate profile, colima start testprofile --cpu 4 --memory 6 --disk 100 --vm-type=qemu --mount-type=sshfs --dns=1.1.1.1 and docker context use testprofile. It's risk free and allows trying out different things without destroying anything.

pharmaline commented 1 year ago

Same issue with wy macbook running ddev with Ventura 13.4.1 .. ddev cypress-open

Cypress failed to start.

This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies

Please refer to the error below for more details.


Command was killed with SIGTRAP (Debugger breakpoint): /root/.cache/Cypress/12.6.0/Cypress/Cypress --no-sandbox --smoke-test --ping=202


Platform: linux-x64 (Debian - 11.6) Cypress Version: 12.6.0 ... any ideas where to look after?

rfay commented 1 year ago

Hi @pharmaline - If you're on a new macbook (Apple Silicon/m1/m2) then this should have been using an arm64 platform, not linux-x64. But you have "Platform: linux-x64 (Debian - 11.6)"

What's going on? Are you on an amd64/Intel machine?

pharmaline commented 1 year ago

Hi @rfay , its an 2,3 GHz 8-Core Intel Core i9 , so Intel machine... seems to be right (however there is Debian as Platform given), but on first post of this issue, its the same.

rfay commented 1 year ago

Hmm,

Cypress 12.6.0 is well before that issue. Time to try https://github.com/cypress-io/cypress/releases/tag/v12.16.0 ?

pharmaline commented 1 year ago

Ok @rfay , i gave it a try, changed docker-compose.cypress.yaml to

ddev-generated

services: cypress: image: cypress/included:12.16.0 then ddev restart and ddev cypress-open and get

Cypress failed to start.

This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies

Please refer to the error below for more details.


Command was killed with SIGTRAP (Debugger breakpoint): /root/.cache/Cypress/12.16.0/Cypress/Cypress --no-sandbox --smoke-test --ping=350


Platform: linux-x64 (Debian - 11.6) Cypress Version: 12.16.0 Failed to run cypress-open : exit status 1

Seems nothing to be changed. Even did brew updat to be up to date

rfay commented 1 year ago

You need to remove the #ddev-generated when you take over the docker-compose.cypress.yaml file. And be aware that I know absolutely nothing about Cypress. I'm just pointing you to similar issues in the queue.

pharmaline commented 1 year ago

So we are at least 2 weithout any knowledge about Cypress... Seems a trivial reason not to start up, but i cannot images waht is wrong... perhaps i try a solo installation in a seperate ddev installation not in a project. To get it clear i am installing it in a typo3 ddev environment this case still Typo3 9.5

martyspain commented 1 year ago

I've found a partial solution to the problem, after finding this comment on a GH issue on the official Cypress repo.

It looks like setting the HOME environment variable in docker-compose.cypress.yaml to /root resolves the permissions problem that's the cause of these SIGTRAP failures.

environment:
      - CYPRESS_baseUrl=${DDEV_PRIMARY_URL}
      - DISPLAY
      - HOME=/root

This allows ddev cypress-open and ddev cypress-run to work, though there are still some errors showing up on my screen and I can't work out where to access Cypress after running ddev cypress-open. However, I can now at least run my integration tests using ddev cypress-run, which is a big step forward.

I hope the above helps some others struggling with this or similar issues.

tyler36 commented 1 year ago

I came across that a couple of days ago. Hopefully get a chance tomorrow to push that to GA and see if that works.

pharmaline commented 1 year ago

I cann assist. Afer Adding - HOME=/root id did a ddev restart... an then

 t9 % ddev cypress-open

DevTools listening on ws://127.0.0.1:44435/devtools/browser/57bd1af9-9bdb-4494-a56f-2c12a4dcbd23
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[442:0707/201601.614589:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

I guess these are the errors you mentioned... Just wanted to show up what errors occur afterward... So After control-c Failed to run cypress-open : exit status 130

ultimike commented 1 year ago

@martyspain @pharmaline Thanks for the info - I added the HOME=\root bit to my docker-compose.cypress.yaml and am at the exact same point as @pharmaline now. So, it seems like we are getting closer...

-mike

mandrasch commented 11 months ago

Hi, I'm a first time cypress user.

After I changed environment with help of your posts in docker-compose.cypress.yaml

    environment:
      - CYPRESS_baseUrl=${DDEV_PRIMARY_URL}
      - DISPLAY
      - HOME=/root

I also ran into the libva error

I found this comment from 2 weeks ago: https://github.com/cypress-io/cypress/issues/27741#issuecomment-1716234361

Bumped cypress to

    image: cypress/included:13.2.0

Did a ddev restart, now I get:

ddev cypress-open
DevTools listening on ws://127.0.0.1:41639/devtools/browser/...

That's a good thing, right? 😁 (I have no idea what to do next 😀 ) Thx to tyler for providing this!

tyler36 commented 11 months ago

@mandrasch
Because you are a first time user, I would recommend just using npm to install Cypress to play around. This addon is designed to use the same config files and tests. Once we figure out the issue, you'll be able to swap the local install for the addon.

I think you'll enjoying using cypress.

Firesphere commented 10 months ago

Here's what I did to get it to work on MacOS:

Change some values in the docker-compose:

    user: "1000:1000"
    networks: [default, ddev_default]

    tty: true

    environment:
      - CYPRESS_baseUrl=${DDEV_PRIMARY_URL}
      - DISPLAY=host.docker.internal:0

    volumes:
      # Mount the project root to Cypress's project point
      - "${DDEV_APPROOT}:/e2e"
      # Mount DDEV to allow commands
      - ".:/mnt/ddev_config"
      # Allow X11 forwarding
      - /tmp/.X11-unix:/tmp/.X11-unix

(Note the 1000:100 for the user, and the host.docker.internal:0 for DISPLAY)

Then, I ran, in a terminal: xhost + 127.0.0.1

After restarting DDEV, I got cypress-open working.

tyler36 commented 10 months ago

Great work @Firesphere

For me on WSL, I get the following error when I use DISPLAY=host.docker.internal:0:

[30:1020/032735.418929:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[30:1020/032736.318368:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
[30:1020/032736.318389:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.

Is there something I should configure?

Firesphere commented 10 months ago

I commented very brief before I rushed off to catch a bus, just to not forget.

I'll comment in more detail later tonight when I'm home

tyler36 commented 10 months ago

OK slight correction.

DISPLAY=host.docker.internal:0 does work on my WSL install if I have a X11 server running. About 2 months ago, I moved to a new Win11 PC. I ported my data but not my apps (installing as I needed them). On Win10, I used VcXsrv as my X11 server. However Win11/WSL did not require this so I never setup VcXsrv .

WSL version: 1.2.5.0 Kernel version: 5.15.90.1 WSLg version: 1.0.51 MSRDC version: 1.2.3770 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22621.2428

Firesphere commented 10 months ago

I only have MacOS or Kubuntu, so I can't exactly speak for WSL :)

Versions:

$ ddev --version ddev version v1.22.3

$ colima --version colima version 0.5.6

$ docker -v Docker version 24.0.6, build ed223bc820

$ uname -a Darwin Ichthyocentaurs.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:43:05 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6020 arm64

Here's my full Cypress docker-compose yml for DDEV:

services:
  cypress:
    image: cypress/included:12.6.0
    container_name: ddev-${DDEV_SITENAME}-cypress
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: ${DDEV_APPROOT}
    user: "1000:1000" # Seems to need this instead of the ${USER}
    networks: [default, ddev_default]

    tty: true

    environment:
      - CYPRESS_baseUrl=${DDEV_PRIMARY_URL}
      - DISPLAY=host.docker.internal:0 # Set host display

    volumes:
      # Mount the project root to Cypress's project point
      - "${DDEV_APPROOT}:/e2e"
      # Mount DDEV to allow commands
      - ".:/mnt/ddev_config"
      # Allow X11 forwarding
      - /tmp/.X11-unix:/tmp/.X11-unix

    external_links:
      # Resolve links via DDEV router
      - "ddev-router:${DDEV_HOSTNAME}"

    entrypoint: /bin/bash
    working_dir: /e2e

On MacOS, I also had to run xhost + 127.0.0.1, which should respond with 127.0.0.1 being added to access control list

After that, I could run ddev cypress-open.

tyler36 commented 10 months ago

@Firesphere Could you please try use changing the follow:

-- DISPLAY=host.docker.internal:0 # Set host display
+- DISPLAY=${DISPLAY:-host.docker.internal:0}
Firesphere commented 10 months ago

That takes the $DISPLAY from MacOS or Kubuntu, which again fails at "Missing X server or $DISPLAY"

On MacOS, ssh'ing in to the Cypress box gives me a $DISPLAY of /private/tmp/com.apple.launchd.e2GTZQiXPQ/org.xquartz:0

Which, on MacOS, Cypress has no access to.

A potential solution might be to add .Xauthority, according to some. However I've not found that even to exist on MacOS...

tyler36 commented 10 months ago

So MacOs defines a $DISPLAY but it doesn't point to a X server that can be seen from inside the DDEV container? Interesting.

Firesphere commented 10 months ago

I believe so, and I think it has something to do with Docker on MacOS being sorta docker-inside-a-vm-thing

Firesphere commented 10 months ago

A colleague of mine uses Docker Desktop, and can't make /tmp/.X11-unix a mount in Docker....

Not sure if it's Docker Desktop related, but I expect more people to run in to this....

tyler36 commented 10 months ago

A colleague of mine uses Docker Desktop, and can't make /tmp/.X11-unix a mount in Docker....

I use Docker Desktop (current 4.25.0 ) and WSL (Ubuntu).

pharmaline commented 10 months ago

So, i was filled up and talked at Typo3 camp Rhein Ruhr to Roland Golla, who led me to the point NOT to install cypress on my Mac in Docker, but to install it locally on my computer. And... irt works. For those of you who want to give it a try:

Base is https://github.com/ncatestify/cypressio-base

nem should be actual: npm install -g npm@10.2.3

cypress % npm init with ncatestify/cypressio-base follow instructions and then To get started: cd t95 npm install change baseUrl in cypress.config.ts npx cypress open To get started: cd into your project folder npm install change baseUrl in cypress.config.ts npx cypress open

I did get this working this way on Ventura 13.4.1

gauravgoyal commented 8 months ago

Created a .ddev/docker-compose.local.yaml to keep things isolated for mac M1 and added below

services:
  cypress:
    environment:
      - DISPLAY=host.docker.internal:0
      - HOME=/root

Cypress works successfully post this. However I need to make sure that xquarz application is running before running cypress. Probably adding xquartz in launch script would help here.

tyler36 commented 8 months ago

@gauravgoyal
Thanks for the update. If someone else can confirm this, we can update the docs.

lhridley commented 7 months ago

Here's what I have working, in two different scenarios for a project configured for E2E testing:

Scenario 1

Host

DDEV configuration

DDEV Project

Result

Scenario 2

Host

Same setup as Scenario 1, with the following additions

DDEV configuration

Same setup as Scenario 1, with the following addition to the docker-compose.local.yml file:

services:
  cypress:
    ...
    platform: linux/amd64  ## <=== takes advantage of the Intel emulation provided by Rosetta 2, and runs amd64 images on arm processor

DDEV project

Result

Note