【问题标题】:Not able to run Puppeteer in headless mode on shared runner on Gitlab.com无法在 Gitlab.com 上的共享运行器上以无头模式运行 Puppeteer
【发布时间】:2019-01-16 07:52:28
【问题描述】:

我在 Gitlab.com 上设置了一个私人仓库。我为我的代码编写了一些测试用例,包括在浏览器上运行的 E2E 测试。为此,我使用Puppeteer。我的测试用例是用 node.js 编写的,我使用 MochaNyc 进行测试和覆盖部分。

这是我的示例.gitlab-ci.yml 文件。

image: node:10.14.2

cache:
  paths:
  - node_modules/

stages:
  - test

test_async:
  stage: test
  before_script:
   - apt-get update
   - apt-get install -yyq ca-certificates
   - apt-get install -yyq libappindicator1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
   - apt-get install -yyq gconf-service lsb-release wget xdg-utils
   - apt-get install -yyq fonts-liberation

  script:
   - npm install
   - npm i mocha
   - npm i puppeteer
   - npm i nyc
   - npm test

更新: 现在运行测试时,我在管道构建中收到以下错误:

Failed to launch chrome! spawn chromium ENOENT

浏览器初始化脚本:

browser = await puppeteer.launch({
      headless: true,
      executablePath: 'chromium',
      args: ['--no-sandbox', '--disable-setuid-sandbox'],
      slowMo: 100,
      timeout: 10000
    });

任何帮助将不胜感激。问候

【问题讨论】:

  • 我没有时间调试你的问题,但也许你可以通过google的故障排除部分,它清楚地描述了在受限环境中运行chrome的一些问题并提出了解决方案github.com/GoogleChrome/puppeteer/blob/master/docs/…跨度>
  • 谢谢@nurettin。它有帮助。

标签: node.js gitlab-ci puppeteer


【解决方案1】:

感谢@nurettin。那位医生确实帮了我很多忙。最后通过将我的初始化设置为:

browser = await puppeteer.launch({
      headless: true,
      slowMo: 100,
      timeout: 10000,
      args: ['--no-sandbox'],

    });

.gitlab-ci.yml 中定义的依赖项为我做了诀窍。

【讨论】:

    猜你喜欢
    • 2020-12-28
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多