在 Azure 管道中,如何为无头 Chrome 测试设置 X 显示?
In Azure pipelines, how do you set up X display for headless Chrome testing?
在我们的 Azure Pipeline 中,我们正在尝试 运行 在我们的 Angular 9 应用程序中进行端到端测试,使用以下任务...
package.json 定义了这个...
"scripts": {
...
"e2e": "npm run install-puppeteer && ng e2e"
},
但是当代理 运行执行上述任务时,它会因“无法打开 X 显示”错误而终止...
> 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 ]
一般情况下安装Xvfb就可以解决这种问题。我如何使用 Azure 管道做到这一点?
确实,这是@Hugh Lin 在评论中的回答,但为了后代的利益,我创建了一个 bash 任务,其中 运行 我存储库中的一个脚本。脚本包含
#!/bin/bash
xvfb-run --auto-servernum --server-args='-screen 0, 1920x1080x24' npm run test -- --watch=false --codeCoverage=true
然后测试 运行 成功。
在我们的 Azure Pipeline 中,我们正在尝试 运行 在我们的 Angular 9 应用程序中进行端到端测试,使用以下任务...
package.json 定义了这个...
"scripts": {
...
"e2e": "npm run install-puppeteer && ng e2e"
},
但是当代理 运行执行上述任务时,它会因“无法打开 X 显示”错误而终止...
> 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 ]
一般情况下安装Xvfb就可以解决这种问题。我如何使用 Azure 管道做到这一点?
确实,这是@Hugh Lin 在评论中的回答,但为了后代的利益,我创建了一个 bash 任务,其中 运行 我存储库中的一个脚本。脚本包含
#!/bin/bash
xvfb-run --auto-servernum --server-args='-screen 0, 1920x1080x24' npm run test -- --watch=false --codeCoverage=true
然后测试 运行 成功。