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:
I use the following shell script to start Selenium and Xvfb:
#!/bin/sh
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 would like to know how I can get sendfkeys() working with headless Chrome inside a Vagrant VM. Any help is greatly appreciated.
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:
#!/bin/sh
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With