我尝试使用 puppeteer 运行 ChromeHeadless 来运行我的单元测试。但是我无法启动 ChromeHeadless 并出现以下错误。
03 07 2019 03:19:25.066:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
03 07 2019 03:19:25.071:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
03 07 2019 03:19:25.080:INFO [launcher]: Starting browser ChromeHeadless
03 07 2019 03:19:25.573:ERROR [launcher]: Cannot start ChromeHeadless
/workspace/node_modules/puppeteer/.local-chromium/linux-672088/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
03 07 2019 03:19:25.574:ERROR [launcher]: ChromeHeadless stdout:
03 07 2019 03:19:25.574:ERROR [launcher]: ChromeHeadless stderr: /workspace/node_modules/puppeteer/.local-chromium/linux-672088/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
在我的Karma.conf.js中我有::
browsers : ['ChromeHeadlessCustom'],
customLaunchers: {
ChromeHeadlessCustom: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-setuid-sandbox']
}
},
云构建.yaml ::
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
id: 'Install Puppeteer'
args: ['install', 'puppeteer']
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
id: 'Test'
args: ['run', 'test']
答案1
选定的 docker 容器没有运行 chrome 所需的软件包;您应该更改为更新的容器;
cloud build.yaml 运行 headless-chrome 测试(此外,您还应该将 puppeeter 放在 package.json 中的依赖项中):
- name: 'buildkite/puppeteer'
args: ['npm','install']
- name: 'buildkite/puppeteer'
args: ['npm', 'run', 'test', ]