Protractor: sendKeys function does not work with headless chrome.

Created on 16 Jun 2017  路  13Comments  路  Source: angular/protractor

Bug report

When I am trying to run protractor in headless environment using headless chrome (v 59), I get error on the point where sendKeys() function is tried to run.

  • Node Version: 6.1.2
  • Protractor Version: 5.1.2
  • Angular Version: 1.4.1
  • Browser(s): Chrome headless
  • Operating System and Version Linux homestead 4.4.0-66-generic #87-Ubuntu
  • Your protractor configuration file
capabilities: {
      'browserName': 'chrome',
      'chromeOptions': {
        'args': ['--window-size=1800,2000', '--headless', "--disable-gpu"]
      }
    },
  • A relevant example test
    Use of sendKeys anywhere in the tests
  • Output from running the test

``` Message:
WebDriverError: unknown error: an X display is required for keycode conversions, consider using Xvfb
(Session info: headless chrome=59.0.3071.86)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.4.0-66-generic x86_64)
Stack:
WebDriverError: unknown error: an X display is required for keycode conversions, consider using Xvfb
(Session info: headless chrome=59.0.3071.86)
(Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.4.0-66-generic x86_64)
at WebDriverError (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/error.js:27:5)
at Object.checkLegacyResponse (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/error.js:505:15)
at parseHttpResponse (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebElement.sendKeys()
at Driver.schedule (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/webdriver.js:816:17)
at WebElement.schedule_ (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/webdriver.js:1921:25)
at WebElement.sendKeys (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/webdriver.js:2084:19)
at actionFn (/home/vagrant/Code/cms/node_modules/protractor/lib/element.ts:94:34)
at Array.map (native)
at actionResults.getWebElements.then (/home/vagrant/Code/cms/node_modules/protractor/lib/element.ts:484:67)
at ManagedPromise.invokeCallback_ (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/promise.js:1366:14)
at TaskQueue.execute_ (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/promise.js:2970:14)
at TaskQueue.executeNext_ (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/promise.js:2953:27)
at asyncRun (/home/vagrant/Code/cms/node_modules/selenium-webdriver/lib/promise.js:2813:27)Error
at ElementArrayFinder.applyAction_ (/home/vagrant/Code/cms/node_modules/protractor/lib/element.ts:482:23)
at ElementArrayFinder.(anonymous function) [as sendKeys] (/home/vagrant/Code/cms/node_modules/protractor/lib/element.ts:96:21)
at ElementFinder.(anonymous function) [as sendKeys] (/home/vagrant/Code/cms/node_modules/protractor/lib/element.ts:873:14)
````

  • Steps to reproduce the bug
    Use sendKeys in the tests and try to run protractor in headless environment without xvfb
  • The URL you are running your tests against (if relevant)
    Not applicable

Most helpful comment

FYI: ChromeDriver 2.31 has been released yesterday.
The release fixed the mentioned bug in my test environment.

All 13 comments

Just a check, but have you tried upgrading nom to 6.9.x because that's was Protractor requires?

No, my node version is still old one. I will try to do the same over the weekend to see if it works and will get back to you. Thanks.

By the way, I've tried to test with:

  • Node Version: 7.5.0
  • Protractor Version: 5.1.2
  • Angular Version: 4
  • Browser(s): Chrome headless 59.0.3071.104
  • Operating System and Version: Mac oSX Siera 10.12.5 (16F73)

And it's working with .sendKeys('string'), so I'm wondering what the node upgrade will do for you. Do you also use NVM, could be useful to easily switch between node versions

Thanks for the tip on nvm.
I installed node 8.1.2 but I still get the same issue. I have installed homestead vm on my mac and running these tests on that instead of mac. I am in the process of automating the tests so there is no point in trying and make it work on Mac OS. Any clues?

    Failed: unknown error: an X display is required for keycode conversions, consider using Xvfb
      (Session info: headless chrome=59.0.3071.104)
      (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.4.0-66-generic x86_64)

The error you get now is related to this question on SO

https://stackoverflow.com/q/44597107/5911978

I would suggest to close the question here because, in my opinion, it is not related to Protractor, but or Chrome/Chromedriver/OS.

Tnx

Agreed; this is going to be an issue with your OS. I'm going to go ahead and close this.

@wswebcreation thanks for troubleshooting!

For the record, the problem is in chromedriver and is/will be fixed in 2.31, see https://bugs.chromium.org/p/chromedriver/issues/detail?id=1772

I will be very happy once that happens.

We had same issue of needing 'native headless sendkeys' for testing file uploads.
Until chromedriver 2.31 is released there is a patched 2.30 here that worked for us:
https://github.com/davidthornton/chromedriver-2.31/blob/master/chromedriver

The official 2.31 is not released but when it is it will deprecate above link of course:
https://sites.google.com/a/chromium.org/chromedriver/downloads

FYI: ChromeDriver 2.31 has been released yesterday.
The release fixed the mentioned bug in my test environment.

I am still not able get sendkeys working on 2.31. Is it resolved?

Yeah it is resolved. I have been running my tests with headless chrome smoothly now. What error do you get?

Can confirm this fixes testrun issues with the sendKeys() method (in my case inside nightwatch as either setValue() or keys()). Thanks for sharing!

Was this page helpful?
0 / 5 - 0 ratings