Protractor throws error an X Display is required f

2019-09-15 04:15发布

问题:

While running ng e2e I get the following

✓ 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)

Configuration:

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 } }));
  }
};

From the following link, it seems we do not need Xvfb, so what would be the right configuration?

For now followed configuration from here: Using Headless Chrome.

回答1:

Workaround to install chromedriver 2.31

As mentioned in this bug report, davidthornton has compiled a binary of chromedriver-2.31, which includes the fix: https://github.com/davidthornton/chromedriver-2.31

I've successfully used this by adding this oneliner to my ci install script:

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"

Is 2.31 released, yet?

Let's hope they'll release chromedriver 2.31 soon!

Check the releases here: https://sites.google.com/a/chromium.org/chromedriver/downloads



回答2:

Above issue was due to sendkeys. As of now there is no solution with just headless browser and sendkeys, refer to Issue.

It works with xvfb for now.

Provision 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