在Azure管道中,如何为无头Chrome测试设置X显示器?

hfyxw5xn  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(138)

在我们的Azure管道中,我们尝试在Angular 9应用程序中运行端到端测试,使用以下任务。


的数据
package.json定义了...

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

字符串
但当代理运行上述任务时,它会因“无法打开X显示”错误而死亡...

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



> [email protected] install-puppeteer /home/vsts/work/1/s 

> cd node_modules/puppeteer && npm run install 



> [email protected] 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 [email protected] test script. 

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

24 verbose exit [ 1, true ]


通常情况下,这类事情是通过安装Xvfb来处理的。我如何使用Azure管道来实现这一点?

q8l4jmvw

q8l4jmvw1#

实际上,这是@Hugh Lin从评论中得到的答案,但为了子孙后代的利益,我创建了一个bash任务,它在我的存储库中运行一个脚本。

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

字符串
然后测试成功运行。

相关问题