本文介绍了量角器sendkeys不起作用:按键代码转换需要x显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用无头Chrome在Vagrant VM中运行Protractor e2e测试.我设法通过使用Xvfb使其正常工作,但是当我运行测试以填写表格时出现错误:未知错误:密钥代码转换需要X显示,请考虑使用Xvfb

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

所有测试运行正常,但是一旦我使用getKeys()(例如element(by.model('user.email')).sendKeys('admin');),即使我已经使用了,我也会收到此错误消息使用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.

我正在跑步:

  • 使用Yeoman角全栈生成器生成的AngularJS示例应用程序
  • 与nvm一起安装的Nodejs版本0.10.30
  • 流浪者1.6.3
  • VirtualBox 4.3.14
  • 主机操作系统Ubuntu 14.04 32位
  • 来宾操作系统Ubuntu 14.04 32位
  • chrome 37.0.2062.94
  • chromedriver 2.10.267517

我使用以下shell脚本启动Selenium和Xvfb:

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

webdriver-manager启动&

webdriver-manager start &

Xvfb:1 -ac -screen 0 1280x1024x8&

Xvfb :1 -ac -screen 0 1280x1024x8 &

export DISPLAY =:1

export DISPLAY=:1

我还向/opt/google/chrome/google-chrome添加了导出DISPLAY =:1".同样,没有sendKeys()的测试也可以正常运行.

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

我到目前为止所做的事情:

  • 我正在运行32位Ubuntu,因此我下载了32位chromedriver 2.10,但这没有帮助
  • 我用--verbose运行了chromedriver并检查了日志,但这只显示了相同的错误
  • 我摆弄Xvfb屏幕尺寸设置,也无济于事
  • 我在此处检查了一些源代码: https://github.com/bayandin/chromedriver/blob/master/keycode_text_conversion_x.cc ,并在第196行找到了错误消息.当命令gfx :: GetXDisplay()(第193行)没有获得显示对象时,将触发该事件.我怀疑这可能只是我在/opt/google/chrome/google-chrome中导出的DISPLAY变量,但我不确定,也不知道如何解决它.
  • 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.

我想知道如何在Vagrant VM内使用sendfkeys()与无头Chrome一起工作.任何帮助将不胜感激.

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

推荐答案

确保 seleniumAddress:'http://localhost:4444/wd/hub'与您的硒服务器匹配,并避免设置chromeOnly,因为这将有效避免使用无头硒服务器.

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.

此外,Xvfb需要在webdriver-manager之前运行,并且您错过了xvfb-run,因为您似乎需要它来执行为您X权舞:

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 &

如果您有兴趣,我会设置一个基于Docker的无头解决方案,并提供可选的VNC访问和视频录制功能: https://github.com/elgalu/docker-selenium

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

这篇关于量角器sendkeys不起作用:按键代码转换需要x显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 09:02