Bitbucket pipeline Your system is missing the dependency: Xvfb
Asked Answered
D

2

17

I'm trying to add cypress to the bitbucket pipeline but it tells me that I need to install Xvfb and I don't know how to keep going. This is my bitbucket.pipelines.yml

#  Template NodeJS build

#  This template allows you to validate your NodeJS code.
#  The workflow allows running tests and code linting on the default branch.

image: node:14.15.4

pipelines:
  default:
    - step:
        name: Build
        script:
          - npm install
          - npm run lint
          - npm run cypress:run

This is my package.json scripts

"scripts": {
    "cypress:open": "cypress open",
    "cypress:run": "npx cypress run --record --key xxxxxxxxxxxx"
}

and the test are running fine locally enter image description here

But in the pipeline I'm getting this error:

+ npm run cypress:run
> [email protected] cypress:run /opt/atlassian/pipelines/agent/build
> npx cypress run --record --key 70004462-62d4-42ce-b359-5bff73d8b001
It looks like this is your first time using Cypress: 6.5.0
[16:30:09]  Verifying Cypress can run /root/.cache/Cypress/6.5.0/Cypress [started]
[16:30:09]  Verifying Cypress can run /root/.cache/Cypress/6.5.0/Cypress [failed]
Your system is missing the dependency: Xvfb
Install Xvfb and run Cypress again.
Read our documentation on dependencies for more information:
https://on.cypress.io/required-dependencies
If you are using Docker, we provide containers with all required dependencies installed.
----------
Error: spawn Xvfb ENOENT
----------
Platform: linux (Debian - 9.13)
Cypress Version: 6.5.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] cypress:run: `npx cypress run --record --key xxxxxxxxx`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] cypress:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Diglot answered 25/2, 2021 at 17:18 Comment(2)
Did you read docs.cypress.io/guides/continuous-integration/…?Wildebeest
Yes, but I didn't understand it... I'm not familiar with LinuxDiglot
M
19

Xvfb is an in-memory display server for a UNIX-like operating system, in your case Linux (Debian - 9.13). This is a system-level dependency that cypress assumes is installed beforehand. In the case of bitbucket env, this is not installed and hence this error. This is primarily used for Display (UI) in case of headed browsers while running cypress.

There are few easy workarounds here:

  1. Installing the dependency manually: I won't suggest this as you might miss out few more dependencies unless you thoroughly look into all the dependencies.

  2. Run headless browsers:: Headless browsers don't use Xvfb, so won't be facing this exact error but as I said in point 1, there can be other issues. Command will become cypress run --headless

  3. Use Cypress provided Docker images (Suggested): I can see that you are using the node:14.15.4 image for this build. Instead of that, use a cypress provided official base images for whatever node version you want to run (Look for different node version in tags). If you look into the Dockerfile, you will see that they have taken an effort to install the dependencies needed to run Cypress inside the docker (You can see Xvfb there).

Also, look for already open issues when you get stuck in cypress-related issues, they have a very active and helpful issues section. I found this same issue in there: https://github.com/cypress-io/cypress/issues/14457

Molton answered 27/2, 2021 at 10:59 Comment(1)
Just --headless did not work because: "Electron cannot be run without an X11 server. Cypress's default browser is Electron and won't be able to launch if you set this environment variable." "Chromium based browsers and Firefox can spawn without Xvfb when run via the --headless flag. If you're testing against either of those browsers using the --browser flag, you can opt out of Cypress spawning an X11 server by setting the environment variable ELECTRON_RUN_AS_NODE=1" docs.cypress.io/guides/continuous-integration/…Gallipot
G
6

Cypress provides the dependencies for CI.

Linux

  • Ubuntu/Debian
apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
  • CentOS
yum install -y xorg-x11-server-Xvfb gtk2-devel gtk3-devel libnotify-devel GConf2 nss libXScrnSaver alsa-lib

reference: https://docs.cypress.io/guides/continuous-integration/introduction#Dependencies

Govan answered 22/4, 2022 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.