playwright: [Bug] - Firefox with Jenkins inside Docker does not work

Context: Project: https://github.com/APAODUQS/playwright-demo Playwright image: mcr.microsoft.com/playwright:v1.20.1-focal Jenkins Server version: 2.277.4

#Jenkinsfile
pipeline {
   agent { docker { image 'mcr.microsoft.com/playwright:v1.20.1-focal' } }
   stages {
      stage('e2e-tests') {
         steps {
            sh 'npm install'
            sh 'npm run test -- --project Chrome --grep @playwright'
         }
      }
   }
}

Describe the problem: I am trying to run the tests from a jenkins build as the documentation indicates: https://playwright.dev/docs/ci#jenkins, but when I try to run it with the previous configuration, with the playwright docker image I get this error: Screen Shot 2022-03-31 at 5 31 52 PM

Then, when I run:

        sh '''
            npm install
            npx playwright install chrome
            npm run test -- --project Chrome --grep @playwright
        '''

I get the error: Screen Shot 2022-03-31 at 5 36 54 PM

Then I tried to run it with tue command npx playwright install:

        sh '''
            npm install
            npx playwright install
            npm run test -- --project Chrome --grep @playwright
        '''

And I get the same first error.

I have tried a lot of things but they still are not working. Could you help me or suggest me how I could run it?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (10 by maintainers)

Most upvoted comments

Thanks @APAODUQS! Is that output from a run in a container? If not (and theirs a display), remove the xvfb-run bit—that’s only needed if there isn’t a display available already. That looks like a different error from https://github.com/microsoft/playwright/issues/13230#issuecomment-1086195132.

Since there are now several confirmations that it works for some Jenkins Docker configurations and the surface area for configuring Jenkins and its agents is large, folks in the Jenkins community will likely be better able to help you troubleshoot.

Thanks for your patience, and feel free to post back what you find!

@spursbob @APAODUQS I’m failing to repro the issue on my Jenkins instance. /tmp is writeable and the tests (headful and headless for firefox) all pass:

Screen Shot 2022-04-06 at 10 36 37 AM

Here is the full code (Jenkinsfile and test code for the pipeline above): https://github.com/rwoll/jenkins-playground/tree/8ecb7cc77328b5f484483accd421b29909dfe765

Please try running that repo on your Jenkins instance and let us know if it passes or fails (in the same or different way from the issue reported here). If it passes (and is therefore not a repro), then we’ll need you to link us to a repro repo from you in order to debug further.

We’re using os.tmpdir() in our Node code when choosing these tmp directories. If that’s not writable on yours Jenkins installation, that seems like it would break more than just Playwright. Perhaps the Jenkins agent is not configured properly and there are some overall permissions issues?

Thanks for your patience! Happy Jenkins debugging!

You and I seem to be in the same boat. My hunch is we can’t write to the /tmp dir to create the profile. See “-profile /tmp/playwright_firefoxdev_profile-7i2bQF” in your output.

I’m evaluating Playwright for my organisation and thinking of dropping Playwright as an option which is a shame as it’s my favourite.

I got this error:


+ PWDEBUG=console npx playwright test --config=playwright.config.ts --project Firefox --grep @playwright

Running 1 test using 1 worker

�[1A�[2K
�[1A�[2K[1/1] [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright
�[1A�[2K  1) [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright =====

    browserType.launch: Protocol error (Browser.enable): Browser closed.
    ==================== Browser output: ====================
    <launching> /ms-playwright/firefox-1319/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-va24Dc -juggler-pipe -silent
    <launched> pid=365
    [pid=365][err] Error: no DISPLAY environment variable specified
    =========================== logs ===========================
    <launching> /ms-playwright/firefox-1319/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-va24Dc -juggler-pipe -silent
    <launched> pid=365
    [pid=365][err] Error: no DISPLAY environment variable specified
    ============================================================





�[1A�[2K
  1 failed
    [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright ======

Do you get the same error when running:

DEBUG=pw:api,pw:browser npx playwright test --config=playwright.config.ts --project Firefox --grep @playwright

I think PWDEBUG=console is running in headed mode so masking your actual issue.

I got this:

[](http://localhost:8081/job/playwright-demo/job/main/145/console#)Run Tests
[Pipeline] sh
+ DEBUG=pw:api,pw:browser npx playwright test --config=playwright.config.ts --project Firefox --grep @playwright

Running 1 test using 1 worker


[Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright
  pw:api => browserType.launch started +0ms

  pw:browser <launching> /ms-playwright/firefox-1319/firefox/firefox -no-remote -headless -profile /tmp/playwright_firefoxdev_profile-7i2bQF -juggler-pipe -silent +0ms

  pw:browser <launched> pid=345 +5ms

  pw:browser [pid=345][err] *** You are running in headless mode. +428ms

  pw:browser [pid=345][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.670878) [GFX1-]: glxtest: libpci missing +243ms

  pw:browser [pid=345][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.670878) |[1][GFX1-]: glxtest: Unable to open a connection to the X server (t=0.670963) [GFX1-]: glxtest: Unable to open a connection to the X server +0ms

  pw:browser [pid=345][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.670878) |[1][GFX1-]: glxtest: Unable to open a connection to the X server (t=0.670963) |[2][GFX1-]: glxtest: libEGL initialize failed (t=0.670981) [GFX1-]: glxtest: libEGL initialize failed +0ms

  pw:browser [pid=345][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.670878) |[1][GFX1-]: glxtest: Unable to open a connection to the X server (t=0.670963) |[2][GFX1-]: glxtest: libEGL initialize failed (t=0.670981) |[3][GFX1-]: No GPUs detected via PCI (t=0.671006) [GFX1-]: No GPUs detected via PCI +0ms

  pw:browser [pid=345][err] Unable to revert mtime: /ms-playwright/firefox-1319/firefox/fonts +93ms

  pw:browser [pid=345][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +224ms

  pw:browser [pid=345][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +10ms

  pw:browser [pid=345][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +7ms

  pw:browser [pid=345][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +3ms

  pw:browser [pid=345][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. +36ms

  pw:browser [pid=345][err]  +60s

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:49.932: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

  pw:browser [pid=345][err]  +2ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:49.933: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

  pw:browser [pid=345][err]  +0ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:49.933: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

  pw:browser [pid=345][err]  +0ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:49.934: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

  pw:browser [pid=345][err]  +5ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:49.939: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +1ms

  pw:browser [pid=345][err]  +482ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:50.421: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

  pw:browser [pid=345][err]  +0ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:50.422: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

  pw:browser [pid=345][err]  +0ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:50.422: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +1ms

  pw:browser [pid=345][err]  +0ms

  pw:browser [pid=345][err] (firefox:345): dconf-CRITICAL **: 20:14:50.422: unable to create directory '/.cache/dconf': Permission denied.  dconf will not work properly. +0ms

[1/1] [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright
  1) [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright =====

    Timeout of 90000ms exceeded.


  pw:browser [pid=345] <kill> +29s

  pw:browser [pid=345] <will force kill> +0ms

  pw:browser [pid=345] starting temporary directories cleanup +1ms

  pw:browser [pid=345] finished temporary directories cleanup +7ms

  Slow test file: [Firefox] › example.spec.ts (2m)
  Consider splitting slow test files to speed up parallel execution

  1 failed
    [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright ======

I got this error:


+ PWDEBUG=console npx playwright test --config=playwright.config.ts --project Firefox --grep @playwright

Running 1 test using 1 worker

�[1A�[2K
�[1A�[2K[1/1] [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright
�[1A�[2K  1) [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright =====

    browserType.launch: Protocol error (Browser.enable): Browser closed.
    ==================== Browser output: ====================
    <launching> /ms-playwright/firefox-1319/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-va24Dc -juggler-pipe -silent
    <launched> pid=365
    [pid=365][err] Error: no DISPLAY environment variable specified
    =========================== logs ===========================
    <launching> /ms-playwright/firefox-1319/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-va24Dc -juggler-pipe -silent
    <launched> pid=365
    [pid=365][err] Error: no DISPLAY environment variable specified
    ============================================================





�[1A�[2K
  1 failed
    [Firefox] › example.spec.ts:13:3 › My tests set › Get started with Playwright @playwright ======

Do you get the same error when running:

DEBUG=pw:api,pw:browser npx playwright test --config=playwright.config.ts --project Firefox --grep @playwright

I think PWDEBUG=console is running in headed mode so masking your actual issue.

Error: no DISPLAY environment variable specified

Are you running firefox in headful mode? This error message usually indicates a headful browser is running without a display.

In CI, you’ll want to put xvfb-run in front of your commands so a virtual display is used:

xvfb-run npm run test

Ref: https://playwright.dev/docs/ci#running-headed

Awesome!

I have problems only with firefox,

You can enable tracing and view the trace of one of your failed FFox runs. Alterntively, focus one test, and run with DEBUG="pw:*" env var set to get a dump of logs. Share here (after skimming them for anything sensitive)! If you’re getting an error at a specific part of your test, please include the line(s) and the exact error message.

I don’t have expertise with Jenkins, nor do I have a Jenkins instance handy to test. I suspect Jenkins is running your commands inside the docker container as Jenkins user, so it can’t do the root commands needed for the npx playwright install.

Can you try the following where you have Jenkins break up the building of the test image and actually running the tests?

Dockerfile

FROM mcr.microsoft.com/playwright:v1.20.1-focal
RUN npx playwright@1.20.1 install chrome

Jenkinsfile

pipeline {
    agent { dockerfile true }
   stages {
      stage('e2e-tests') {
         steps {
            sh 'npm install'
            sh 'npm run test -- --project Chrome --grep @playwright'
         }
      }
   }
}

I’ll cross post to in the community chat as I’m not a Jenkins user!

            npm install
            npx playwright install chrome
            npm run test -- --project Chrome --grep @playwright

looks correct. Can you add whoami to see what user Jenkins is running in your container?