webdriverio-community / wdio-electron-service

WebdriverIO service for testing Electron applications
https://webdriver.io
MIT License
34 stars 15 forks source link

wdio-electron-service & docker: DevToolsActivePort file doesn't exist #46

Closed joonne closed 2 years ago

joonne commented 2 years ago

Hey, trying to run cucumber tests against electron inside docker in Jenkins and we're seeing this kinda error:

Request failed with status 500 due to unknown error: Chrome failed to start: exited abnormally.
(DevToolsActivePort file doesn't exist)
(The process started from chrome location ... is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Internet suggests that I should be passing --disable-dev-shm-usage flag for the chromium, but haven't been able to do that. Any helpers or advice that I might have overlooked?

I'm doing a migration from spectron to wdio at the moment. The docker entrypoint making use of xvfb was configured already for spectron and I guess it should work similarly for the wdio also?

wdio.conf.ts

  services: [
    [
      'electron',
      {
        appPath: join(__dirname, '../../../package'),
        appName: productName,
        appArgs: [
          "--disable-infobars", // not sure if this is needed
          "--disable-dev-shm-usage",
          "--no-sandbox", // not sure if this is needed
          "--headless",  // not sure if this is needed
        ],
        chromedriver: {
          port: 9519,
          logFileName: 'wdio-chromedriver.log',
        },
      },
    ],
  ],

Grateful for any tips :)

goosewobbler commented 2 years ago

Hi @joonne,

This is a very common and irritating error, one which I struggled with for quite a few days over the initial development of wdio-electron-service (back then it was still a Spectron fork). There's a lot of "fixes" for this detailed on the web which are out of date or just plain wrong. I couldn't get the tests to work on github actions across platforms and what solved it for me in the end was a lot of trial and error with combinations of flags, some of which you mention, and additionally using the xvfb github action fixed it on linux.

I left the flag combinations which worked for me (across Linux, MacOS & Windows) on github actions in the service so you shouldn't need to pass them in appArgs:

https://github.com/webdriverio-community/wdio-electron-service/blob/main/src/service.ts#L121

Could be that the isCI check is failing, if you check the wdio logs (need to be set to a minimum level of debug) you should be able see the exact browsercapabilities set for a given run which includes the args passed to chromium.

You might also want to put some additional debug into your local copy of the service.

Even if the flags currently specified are being applied correctly in all cases, I don't expect that they will fix all instances of this error; if you manage to find a chromium flag or another change to the service that fixes your instance we can see about getting that (and potentially any additional useful debug logging) merged in.

joonne commented 2 years ago

Hey, thanks for the reply!

I'm currently trying to debug if the flags from isCI are passed down to the app, and also trying to run locally the service but struggling a bit with the npm linking etc. I'll try to come up with something that works for our use case and then submit PR or some other input of the results. It was already super relieving that I was kinda on the right track and all of this trial & error is needed as it is an unknown issue. Thanks :open_hands:

goosewobbler commented 2 years ago

No problem, good luck. I knew it wouldn't be long before someone would be experiencing this issue with the service.

christian-bromann commented 2 years ago

I think it would be nice if we document solutions to this problem, maybe in the README.md so that people know what to do without having to search for years.

goosewobbler commented 2 years ago

@christian-bromann yes, I'll use this issue as a tracker for that as any documentation may also be affected by the OP's findings.

EDIT: created a new issue for docs update, better to keep things separate.

joonne commented 2 years ago

I found out the issue for our problem, it was in fact a missing dependency in our docker image. This was revealed by trying to run chromium (or our own electron app) inside the container. The missing library in our case was libgbm1, and after this was installed, the DevToolsActivePort issue was gone.

Not sure if it is relevant to be documented in this package's documentation, but it seems there are multiple ways to end up in this particular error :man_shrugging: Maybe some notion about running in docker would be in place also?

goosewobbler commented 2 years ago

@joonne glad you fixed it, presumably the library was needed for xvfb to work properly. This particular error is a difficult one but if enough people have the same error and report them here as issues we can keep updating the docs for common solutions.

elboboua commented 1 year ago

I'm having the same issue at the moment. I'm curious what base image you used, @joonne and what other libraries you installed to get this working. I'm trying to get my tests to run on Gitlab Ci. isCi is returning true, so that isn't the problem.

This is my image:

FROM node:16

RUN apt-get update
# git is required for e2e tests
RUN apt-get install -y git
# install libnss3
RUN apt-get install -y libnss3
# install libgbm1
RUN apt-get install -y libgbm1
# install xvfb
RUN apt-get install -y xvfb

I tried installing xvfb as a last ditch move to get the library working on CI. Have you come up with any other debugging steps for this @goosewobbler ?

goosewobbler commented 1 year ago

@elboboua No, I came across it again recently whilst working on #54 though. It was fixed by using this github action, only thing I can suggest is that it you could try duplicating what it does, I think it's more involved than simply installing xvfb.

https://github.com/marketplace/actions/gabrielbb-xvfb-action

elboboua commented 1 year ago

Good news! I was able to resolve this issue on a Gitlab CI runner, and I think I have some information that might be helpful for others with this problem.

There are a list of necessary libraries to run xvfb that I found here. I created my image ensuring that I installed the necessary libraries there.

Here is my dockerfile:

FROM node:16

RUN apt-get update
# git is required for e2e tests
RUN apt-get install -y git
# install libnss3
RUN apt-get install -y libnss3
# install xvfb
RUN apt-get install -y xvfb
# possible dependencies
RUN apt-get install -y zip
RUN apt-get install -y wget
RUN apt-get install -y ca-certificates
RUN apt-get install -y libnss3-dev libasound2 libxss1 libappindicator3-1 libindicator7 gconf-service libgconf-2-4 libpango1.0-0 xdg-utils fonts-liberation libgbm1

Next, before running npm run wdio, you have to include some setup for xvfb in your script. This is my stage snippet, but the most relevant part to people not using Gitlab is the script section:

End-to-End Test:
  stage: e2e test
  dependencies:
    - Make Package
  <<: *install-modules-and-generate-files
  script:
    - echo "Setting up xvfb"
    - export DISPLAY=':99.0'
    - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
    - npm run wdio

Worked like a charm! Hopefully this is helpful, but if you need more explanation, let me know!