cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

Bad Option: --no-sandbox thrown when ELECTRON_RUN_AS_NODE=1 #18224

Closed reidkersey closed 1 year ago

reidkersey commented 3 years ago

Current behavior

I am working to integrate cypress testing into our CI. I was getting Xvfb errors, so I started using the ELECTRON_RUN_AS_NODE=1 env variable.

However, when that variable is fixed, it fixes the Xvfb errors but causes some bad option errors.

build   23-Sep-2021 15:20:16    > cypress run --config-file ./e2e/cypressAngular.headless.json --headless -b chrome
build   23-Sep-2021 15:20:16    
build   23-Sep-2021 15:20:16    It looks like this is your first time using Cypress: 8.3.0
build   23-Sep-2021 15:20:16    
build   23-Sep-2021 15:20:16    [STARTED] Task without title.
error   23-Sep-2021 15:20:17    [FAILED] Cypress failed to start.
build   23-Sep-2021 15:20:17    Cypress failed to start.
build   23-Sep-2021 15:20:17    
build   23-Sep-2021 15:20:17    This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies
build   23-Sep-2021 15:20:17    
build   23-Sep-2021 15:20:17    Please refer to the error below for more details.
build   23-Sep-2021 15:20:17    
build   23-Sep-2021 15:20:17    ----------
build   23-Sep-2021 15:20:17    
build   23-Sep-2021 15:20:17    /usr/local/bamboo/.cache/Cypress/8.3.0/Cypress/Cypress: bad option: --no-sandbox
build   23-Sep-2021 15:20:17    /usr/local/bamboo/.cache/Cypress/8.3.0/Cypress/Cypress: bad option: --smoke-test
build   23-Sep-2021 15:20:17    /usr/local/bamboo/.cache/Cypress/8.3.0/Cypress/Cypress: bad option: --ping=68
build   23-Sep-2021 15:20:17    
build   23-Sep-2021 15:20:17    ----------
build   23-Sep-2021 15:20:17    
build   23-Sep-2021 15:20:17    Platform: linux (CentOS - 7.9.2009)
build   23-Sep-2021 15:20:17    Cypress Version: 8.3.0

Desired behavior

Run the tests

Test code to reproduce

My configuration is:

{
  "fileServerFolder": ".",
  "fixturesFolder": "./e2e/fixtures",
  "integrationFolder": "./e2e/integration",
  "modifyObstructiveCode": false,
  "pluginsFile": "./e2e/plugins/index.ts",
  "supportFile": "./e2e/support/index.ts",
  "video": false,
  "videosFolder": "./e2e/videos",
  "screenshotsFolder": "./e2e/screenshots",
  "chromeWebSecurity": false,
  "baseUrl": "http://localhost:4200",
  "viewportHeight": 960,
  "viewportWidth": 1536,
  "env": {
    "tsConfig": "./e2e/tsconfig.json"
  },
  "ignoreTestFiles": [
    "**/__snapshots__/*",
    "**/__image_snapshots__/*"
  ]
}

I am also setting the env var ELECTRON_RUN_AS_NODE=1 externally by using export ELECTRON_RUN_AS_NODE=1

Cypress Version

v8.3.0 (Also tested in 8.4.1)

Other

Not sure if the issue is related or not, but I can't test this issue locally because when I set the ELECTRON_RUN_AS_NODE=1 env variable I get the error Error: Cannot find module '/Users/reidkersey/Library/Caches/Cypress/8.3.0/Cypress.app/Contents/MacOS/Contents/Resources/app/index.js'

I have also tried setting "ELECTRON_RUN_AS_NODE": "1" in the env section of the config file, and that didn't work, and gave me the Xvfb error.

Wimpert commented 2 years ago

@reidkersey I am facing exactly the same here. Using Cypress 8.7.0, did you find a solution for thie?

reidkersey commented 2 years ago

The only thing I found was to use Chrome instead of Electron

rooby commented 2 years ago

Same thing with Cypress 9.7.0, and I am using Chrome

MarcusElevait commented 2 years ago

Same here with cypress 10.3.1

bobalazek commented 2 years ago

Anyone managed to find a solution for this? Having the same issue in 10.6.0 when running it in docker

sladg commented 1 year ago

Occurring on 10.11.0

ghost commented 1 year ago

used commands: npm insall export ELECTRON_RUN_AS_NODE=1 npm run test

now iam getting this error......Anyone had any solution for this error??

It looks like this is your first time using Cypress: 12.7.0

[STARTED] Task without title. [FAILED] Cypress failed to start. [FAILED] [FAILED] This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies [FAILED] [FAILED] Please refer to the error below for more details. [FAILED] [FAILED] ---------- [FAILED] [FAILED] /apps/jenkins/.cache/Cypress/12.7.0/Cypress/Cypress: bad option: --no-sandbox [FAILED] /apps/jenkins/.cache/Cypress/12.7.0/Cypress/Cypress: bad option: --smoke-test [FAILED] /apps/jenkins/.cache/Cypress/12.7.0/Cypress/Cypress: bad option: --ping=990 [FAILED] [FAILED] ---------- [FAILED]

vahidsamimi commented 1 year ago

used commands: npm insall export ELECTRON_RUN_AS_NODE=1 npm run test

now iam getting this error......Anyone had any solution for this error??

It looks like this is your first time using Cypress: 12.7.0

[STARTED] Task without title. [FAILED] Cypress failed to start. [FAILED] [FAILED] This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies [FAILED] [FAILED] Please refer to the error below for more details. [FAILED] [FAILED] ---------- [FAILED] [FAILED] /apps/jenkins/.cache/Cypress/12.7.0/Cypress/Cypress: bad option: --no-sandbox [FAILED] /apps/jenkins/.cache/Cypress/12.7.0/Cypress/Cypress: bad option: --smoke-test [FAILED] /apps/jenkins/.cache/Cypress/12.7.0/Cypress/Cypress: bad option: --ping=990 [FAILED] [FAILED] ---------- [FAILED]

Same here with cypress 12.7 on Platform: linux-x64 (Red Hat Linux - 8.7) did you fix it? here is my npm command: "cypress:run": " cypress run --component --browser chrome --headless"

sebastian-marinescu commented 1 year ago

Same here with Cypress 12.10.0, also setting ELECTRON_RUN_AS_NODE=1

sebastian-marinescu commented 1 year ago

Yesterday I tried for hours to get it to work with either the atlassian/default-image:3 or a custom docker image that I build on top of that. My Dockerfile I ended up with (while testing) was:

FROM atlassian/default-image:3

RUN apt-get update && \
    apt-get autoremove -y && \
    apt-get install -y --no-install-recommends libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb && \
    rm -rf /var/lib/apt/lists/*

RUN Xvfb -screen 0 1280x1024x24 :99 &

ENV DISPLAY=:99

I also tried with ELECTRON_RUN_AS_NODE=1 before, I tried different Xvfb-commands, but nothing worked.

I've almost given up hope, when I realized that I can use different images per pipeline-step in Bitbucket-Pipeline, so my current solution is (in bitbucket-pipelines.yml):

image: atlassian/default-image:3

pipelines:
  branches:
    master:
      - step:
          name: Build Frontend
          deployment: production
          caches:
            - cypress
            - node
            - npm
          clone:
            depth: full
          script:
            - npm install -g grunt
            - npm install
            - grunt build4CDN
            - declare -x VERSION=$(jq -r '.version' package.json)
            - mkdir frontend
            - mv build/assets/website frontend/${VERSION}
            - mkdir changelog
            - cp changelog.* changelog/
          artifacts:
            - changelog/**
            - frontend/**
      - parallel:
        - step:
            name: Deploy Frontend
            clone:
              depth: 1
            caches:
              - docker
            services:
              - docker
            script:
              - declare -x VERSION=$(jq -r '.version' package.json)
              - pipe: atlassian/ftp-deploy:0.3.7
                variables:
                  USER: $FTP_USER
                  PASSWORD: $FTP_PASS
                  SERVER: $FTP_HOST
                  REMOTE_PATH: './frontend/${VERSION}'
                  LOCAL_PATH: 'frontend/${VERSION}'
        - step:
            name: Deploy Changelog
            clone:
              enabled: false
            caches:
              - docker
            services:
              - docker
            script:
              - pipe: atlassian/ftp-deploy:0.3.7
                variables:
                  USER: $FTP_USER
                  PASSWORD: $FTP_PASS
                  SERVER: $FTP_HOST
                  REMOTE_PATH: './frontend/changelog'
                  LOCAL_PATH: './changelog'
      # TODO: Temporarily use different image until one of the following is resolved:
      # https://github.com/cypress-io/cypress/issues/18183
      # https://github.com/cypress-io/cypress/issues/18224
      # and then use one image for all work / image: nonconformist/bitbucket-cypress:v1-release
      - step:
          name: End-to-End Testing
          image: cypress/browsers:node14.17.6-chrome100-ff98
          clone:
            depth: 1
          caches:
            - cypress
            - docker
            - node
            - npm
          services:
            - docker
          script:
            - npm -g config set user root
            - npm test
            - npm run test:chrome
            - npm run test:firefox

definitions:
  caches:
    npm: $HOME/.npm
    cypress: $HOME/.cache/Cypress

See the last step, it uses a different image: image: cypress/browsers:node14.17.6-chrome100-ff98

The relevant scripts from package.json:

    "test": "npx cypress run --headless --browser electron",
    "test:chrome": "npx cypress run --headless --browser chrome",
    "test:firefox": "npx cypress run --headless --browser firefox",

Hopefully this helps someone 🚀

jordanpowell88 commented 1 year ago

Hopefully this helps someone 🚀

@reidkersey does this solution help you?

sebastian-marinescu commented 1 year ago

Just to clarify: It's more of a workaround, then a real solution. Ideally I think we all would like only one image for the whole build-process, as it saves time and build-budget.

warrensplayer commented 1 year ago

@sebastian-marinescu Can you try the steps towards the bottom of this comment about "warming up" Cypress on initial install?

https://github.com/cypress-io/cypress/issues/17412#issuecomment-1125015667

I believe you are running into the same issue.

reidkersey commented 1 year ago

Hopefully this helps someone 🚀

@reidkersey does this solution help you?

We moved over to playwright for other reasons and it's been working great for us.

warrensplayer commented 1 year ago

For this issue, please follow the progress here: https://github.com/cypress-io/cypress/issues/19868