2

In our Azure Pipeline, we are attempting to run end-to-end tests in our Angular 9 application, using the following task ...

enter image description here

The package.json defines this ...

  "scripts": {
    ...
    "e2e": "npm run install-puppeteer && ng e2e"
  },

but when the agent runs the above task, it dies with "Unable to open X display" error ...

> npm run install-puppeteer && ng test "--watch=false" "--codeCoverage=true" 





> thermo-protect-ui@0.0.0 install-puppeteer /home/vsts/work/1/s 

> cd node_modules/puppeteer && npm run install 





> puppeteer@5.5.0 install /home/vsts/work/1/s/node_modules/puppeteer 

> node install.js 



Chromium is already in /home/vsts/work/1/s/node_modules/puppeteer/.local-chromium/linux-818858; skipping download. 

08 12 2020 18:54:56.858:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/ 

08 12 2020 18:54:56.863:INFO [launcher]: Launching browsers Chrome with concurrency unlimited 

08 12 2020 18:54:56.866:INFO [launcher]: Starting browser Chrome 

08 12 2020 18:54:57.134:ERROR [launcher]: Cannot start Chrome 

[2099:2099:1208/185457.060113:ERROR:browser_main_loop.cc(1439)] Unable to open X display. 



08 12 2020 18:54:57.134:ERROR [launcher]: Chrome stdout: 

08 12 2020 18:54:57.135:ERROR [launcher]: Chrome stderr: [2099:2099:1208/185457.060113:ERROR:browser_main_loop.cc(1439)] Unable to open X display. 



08 12 2020 18:54:57.675:INFO [launcher]: Trying to start Chrome again (1/2). 

08 12 2020 18:54:59.035:ERROR [launcher]: Cannot start Chrome 

22 error Exit status 1 

23 error Failed at the thermo-protect-ui@0.0.0 test script. 

23 error This is probably not a problem with npm. There is likely additional logging output above. 

24 verbose exit [ 1, true ]

Normally this kind of thing is dealt with by installing Xvfb. How do I do that using Azure pipelines?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • 3
    The xvfb package should have been installed in the [hosted ubuntu agent](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md#installed-apt-packages), you should only need to start xvfb. Here is a reference [case](https://developercommunity.visualstudio.com/content/problem/336288/headless-testing-using-xvfb-on-hosted-ubuntu-1604.html). Or you can try to use a [bash task](https://stackoverflow.com/a/50425711/11508192). – Hugh Lin Dec 11 '20 at 09:57

1 Answers1

7

Really this is @Hugh Lin's answer from the comments but for the benefit of posterity I created a bash task which ran a script in my repository. The script contained

#!/bin/bash
xvfb-run --auto-servernum --server-args='-screen 0, 1920x1080x24' npm run test -- --watch=false --codeCoverage=true

Then the tests ran successfully.

Dave
  • 15,639
  • 133
  • 442
  • 830