E2E test fail error: cannot find chrome binary in Linux

E2E test fail error: cannot find chrome binary in Linux

我正在使用 angular 为 gitlab-ci 管道设置 e2e 测试(量角器),实际上我是这个主题的新手。我希望测试是无头的,因为 Gitlab-ci 所在的服务器是 运行 on Linux.

但我总是得到这个错误:

E/launcher - unknown error: cannot find Chrome binary.

对我来说这没有任何意义,因为它编译成功并下载、解压缩 Chromedriver 并获得 1 个 运行 Webdriver 实例,但随后它因上述错误而崩溃。

另外我应该提到的是它在本地工作,但是当我推送它时,它没有。

我已经尝试了一些我发现的东西,例如使用“--no-sandbox”编辑 protractor.conf.js,但它对我不起作用。

在这里你可以看到我的protractor.conf.js

const {SpecReporter} = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './src/**/*.e2e-spec.ts'
  ],
  capabilities: {
    browserName: 'chrome', chromeOptions: {
      args: [
        '--headless',
        '--disable-gpu',
        '--window-size=800,600',
      ]
    }
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function () {
    }
  },
  onPrepare() {
    require('ts-node').register({
      project: require('path').join(__dirname, './tsconfig.e2e.json')
    });
    jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
  }
};

我希望你们能帮助我解决我的问题,非常感谢你们的回答。

通过在 linux 服务器上安装 chrome 修复了它 没有找到其他解决方案

如果您的 Chrome 没有安装在标准位置,您可能必须在 protractor.conf.js 中明确指定它:

capabilities: {
    'browserName': 'chrome',
    "chromeOptions": {
      binary: "/Applications/your_path/Google Chrome.app/Contents/MacOS/Google Chrome"
    },
  },

您可以使用 chrome 选项:

ChromeOptions ChromeOptions = new ChromeOptions();
ChromeOptions.addArguments("--headless", "window-size=1024,768", "--no-sandbox");
driver = new ChromeDriver(ChromeOptions);

我删除了 chromeOptions 中的二进制字段,它找到了在 MacOS 上安装的 Chrome。