electron-userland / spectron

DEPRECATED: 🔎 Test Electron apps using ChromeDriver
http://electronjs.org/spectron
MIT License
1.68k stars 228 forks source link

Error: DevToolsActivePort file doesn't exist #929

Open bsherman-better opened 3 years ago

bsherman-better commented 3 years ago

I'm attempting to build and run a docker container for end to end testing of my electron app. I'm receiving the following error:

    Failed to create session.
    unknown error: Chrome failed to start: exited abnormally.
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location /app/node_modules/spectron/lib/launcher.js is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

      at Object.startWebDriverSession (node_modules/webdriver/build/utils.js:34:15)

Has anyone run into this and found a solution?

nmilev-scribe commented 3 years ago

I'm having the same issue. The app needs some time to show the screen. Might this be the issue?

MauriceWebb commented 3 years ago

@bsherman-better can I see how you are instantiating your spectron's Application instance? I ran into this error when passing webdriverOptions.

sr258 commented 3 years ago

Same issue here. This happens on my MacOS dev machine. When I reboot the computer I can successfully run the tests with Spectron once after reboot. But then all following test runs (until I reboot) produce the error for every test in the suite.

I can see the app opening in the desktop environment and the GUI shows up (and even the tests are executed before my eyes). What's also happening is that a second instance of the app opens up in the dock and immediately closes again about 10 times. Jest also doesn't exist properly once all the tests have failed:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

Versions:

I create the app like this:

app = new Application({
            env: {
                USERDATA: path.join(__dirname, 'data'),
                PORT: PORT,
                NODE_ENV: 'CI'
            },
            path: path.join(
                __dirname,
                '..',
                'node_modules',
                '.bin',
                'electron'
            ),
            args: ['--no-sandbox', path.join(__dirname, '..')]
        });
        return app.start();
sr258 commented 3 years ago

After some digging I found a possible cause for my issue, maybe it will also help others:

The Node process of the electron app remained open after the tests were terminated. The result was that the normal app startup was disrupted and WebDriver couldn't connect to Electron's Chrome instance.

I already had these lines to terminate Spectron after the tests were finished:

        if (app && app.isRunning()) {
            await app.stop();
        }

I added app.mainProcess.abort() and the issue doesn't happen anymore.

zhex900 commented 3 years ago

I still have this problem. I can run headless in the terminal not in the docker container. Can you show me your Dockerfile?

evertonlperes commented 3 years ago

It's been really weird the spectron behaviour on Docker containers. Facing the same issue and I didn't find any good solution for it yet. Here's my Dockerfile for reference:

FROM ubuntu:20.04
ARG GITHUB_CLONE_KEY
ENV GITHUB_CLONE_KEY=$GITHUB_CLONE_KEY \
    WORKDIRAPP=/opt/rd/rancher-desktop \
    BRANCH=main \
    NODE_VER=16

##
## Set up install
##
RUN apt update && apt upgrade -y && apt dist-upgrade -y && apt install software-properties-common wget curl -y \
    && apt update -y \
    && curl -fsSL https://deb.nodesource.com/setup_${NODE_VER}.x | bash - \
    && apt install --no-install-recommends --no-upgrade \
        git nodejs unzip g++ make gnupg2 debconf-utils vim -y

##
## Installing deps for xvfb server
##
RUN apt install xvfb libxtst6 libxss1 libgtk2.0-0 libnss3 libasound2 libgconf-2-4 -y

##
## Pre test image setup
##
WORKDIR $WORKDIRAPP
RUN git clone --depth=1 --branch $BRANCH https://${GITHUB_CLONE_KEY}@github.com/xpto/xpto.git $WORKDIRAPP \
    && npm install || true
WORKDIR $WORKDIRAPP
stephanieraymos commented 2 years ago

I'm having the same issue.

       "before all" hook: startApp for "removed actual name of test":
     Client initialization failed after 10 attempts: RuntimeError Client initialization failed after 10 attempts: 
  Error: unknown error: Chrome failed to start: exited abnormally
    (unknown error: DevToolsActivePort file doesn't exist)
    (The process started from chrome location /my/project/dir/node_modules/spectron/lib/launcher.js is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    (Driver info: chromedriver=76.0.3809.88 (e67b7e2f345cbedc6a24e0074a1a528c724f5915-refs/branch-heads/3809@{#968}),platf
evertonlperes commented 2 years ago

I'm having the same issue.


       "before all" hook: startApp for "removed actual name of test":

     Client initialization failed after 10 attempts: RuntimeError Client initialization failed after 10 attempts: 

  Error: unknown error: Chrome failed to start: exited abnormally

    (unknown error: DevToolsActivePort file doesn't exist)

    (The process started from chrome location /my/project/dir/node_modules/spectron/lib/launcher.js is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

    (Driver info: chromedriver=76.0.3809.88 (e67b7e2f345cbedc6a24e0074a1a528c724f5915-refs/branch-heads/3809@{#968}),platf

Hi @stephanieraymos I had to move away from electron and replaced it by playwright. So far playwright are doing a really good job and no more weird browsers errors.

zhex900 commented 2 years ago

Use Playwright. Don't use this anymore.

stephanieraymos commented 2 years ago

This is a work application and the tests are running fine for others. So getting the whole team on board to switch soon is unlikely. Hoping to find a solution of some kind for now.