Danny Moerkerke Danny Moerkerke - 1 year ago 368
AngularJS Question

Protractor sendkeys not working: an x display is required for keycode conversions

I am trying to run Protractor e2e tests inside a Vagrant VM using headless Chrome.
I managed to get it working by using Xvfb but when I run a test to fill a form I get an error: unknown error: an X display is required for keycode conversions, consider using Xvfb

All tests run fine but as soon as I use getKeys() (e.g. element(by.model('user.email')).sendKeys('admin'); ) I get this error, even though I am already using Xvfb.

I'm running:

  • AngularJS sample app generated with the Yeoman angular-fullstack generator

  • Nodejs version 0.10.30, installed with nvm

  • Vagrant 1.6.3

  • VirtualBox 4.3.14

  • Host OS Ubuntu 14.04 32 bits

  • Guest OS Ubuntu 14.04 32 bits

  • chrome 37.0.2062.94

  • chromedriver 2.10.267517

I use the following shell script to start Selenium and Xvfb:


webdriver-manager start &

Xvfb :1 -ac -screen 0 1280x1024x8 &

export DISPLAY=:1

I also added "export DISPLAY=:1" to /opt/google/chrome/google-chrome.
Again, tests without sendKeys() run fine.

What I have done so far:

  • I'm running 32 bits Ubuntu so I downloaded chromedriver 2.10 32 bits but that didn't help

  • I ran chromedriver with --verbose and checked the logs but that only shows the same error

  • I fiddled with the Xvfb screen dimension settings, didn't help either

  • I checked some source code here: https://github.com/bayandin/chromedriver/blob/master/keycode_text_conversion_x.cc and found the error message on line 196.
    It's triggered when the command gfx::GetXDisplay() (line 193) doesn't get a display object. I suspect that it might be just the DISPLAY variable I export in /opt/google/chrome/google-chrome but I'm not sure and have no idea how to fix it.

I would like to know how I can get sendfkeys() working with headless Chrome inside a Vagrant VM.
Any help is greatly appreciated.

Answer Source

Ensure seleniumAddress: 'http://localhost:4444/wd/hub' matches your selenium server and avoid setting chromeOnly since that will effectively avoid using the headless selenium server.

Also, Xvfb needs to run before webdriver-manager and you're missing xvfb-run given you seem to need it to do the X authority dance for you:


export DISPLAY=:1

Xvfb $DISPLAY -ac -screen 0 1280x1024x8 &
sleep 1

xvfb-run webdriver-manager start &

In case you're interested I've setup a headless docker based solution with optional VNC access plus video recording: https://github.com/elgalu/docker-selenium

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download