量角器抛出错误X无头镀铬需要显示59

时间:2017-05-26 05:14:52

标签: google-chrome protractor selenium-chromedriver headless-browser

在运行ng e2e时,我得到以下内容

✓ should display message saying sign up
✗ should be able to sign up with a valid user
  - Failed: unknown error: an X display is required for keycode conversions, consider using Xvfb
    (Session info: headless chrome=59.0.3071.71)
    (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 3.13.0-48-generic x86_64)
    (Session info: headless chrome=59.0.3071.71)
    (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 3.13.0-48-generic x86_64)

配置:

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

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

从以下link开始,我们似乎不需要Xvfb,那么正确的配置是什么?

现在从这里开始配置:  Using Headless Chrome.

2 个答案:

答案 0 :(得分:0)

上述问题归因于sendkeys。 截至目前,没有无头浏览器和sendkeys的解决方案,请参阅Issue

现在适用于xvfb。

提供xvfb

  • sudo apt-get install -y xvfb
  • sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-cyrillic dbus-x11
  • xvfb-run -a -s“-screen 0 2920x2580x24“ng e2e

答案 1 :(得分:0)

安装chromedriver 2.31

的解决方法

作为mentioned in this bug report,davidthornton编译了chromedriver-2.31的二进制文件,其中包含修复:https://github.com/davidthornton/chromedriver-2.31

我已成功使用此功能,将此oneliner添加到我的ci安装脚本中:

mkdir -p ~/chromedriver && wget https://github.com/davidthornton/chromedriver-2.31/blob/master/chromedriver\?raw\=true -O ~/chromedriver/chromedriver && chmod a+x ~/chromedriver/chromedriver && export PATH="$HOME/chromedriver:$PATH"

是否已发布2.31?

让我们希望他们很快就能发布chromedriver 2.31。

点击此处查看发布:https://sites.google.com/a/chromium.org/chromedriver/downloads