如何为 Chrome 构建远程 Webdriver
我正在尝试针对 Chrome 运行我的 Selenium 测试。当我在本地初始化驱动程序时:
@driver = Selenium::WebDriver.for( :chrome )
一切正常(我已经将 Chrome 二进制文件放在我的 PATH 中) 但是当我尝试远程启动它时:
@driver = Selenium::WebDriver.for(:remote, :url => 'http://' + SELENIUM_HOST + port + webdriver_hub, :desired_capabilities => :chrome)
出现以下错误
Selenium::WebDriver::Error::UnhandledError: 的路径 chromedriver 可执行文件必须由 webdriver.chrome.driver 设置 系统属性;有关更多信息,请参阅 http://code.google.com/p/selenium/wiki/ChromeDriver。最新的 版本可以从下载 http://code.google.com/p/chromium/downloads/list (java.lang.IllegalStateException)
我有点困惑 - 我应该如何设置这个系统属性?我发现这段代码是用 Java 编写的:
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setJavascriptEnabled(true);
caps.setCapability("chrome.binary", "/path/to/where/chrome/is/installed/chrome.exe");
System.setProperty("webdriver.chrome.driver","/path/to/where/you/ve/put/chromedriver.exe");
ChromeDriver driver = new ChromeDriver(caps);
但我的测试是用 Ruby 编写的。 RubyBindings 不讨论这个问题 http://code.google.com/p/硒/wiki/RubyBindings
I am trying to run my Selenium tests against Chrome. When I initialize driver locally:
@driver = Selenium::WebDriver.for( :chrome )
Everything works fine (I already put Chrome binary on my PATH)
But when I try to launch it remotely:
@driver = Selenium::WebDriver.for(:remote, :url => 'http://' + SELENIUM_HOST + port + webdriver_hub, :desired_capabilities => :chrome)
I get the following error
Selenium::WebDriver::Error::UnhandledError: The path to the
chromedriver executable must be set by the webdriver.chrome.driver
system property; for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://code.google.com/p/chromium/downloads/list
(java.lang.IllegalStateException)
I am a bit confused there - how exactly should I set this system property? I found this code written in Java:
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setJavascriptEnabled(true);
caps.setCapability("chrome.binary", "/path/to/where/chrome/is/installed/chrome.exe");
System.setProperty("webdriver.chrome.driver","/path/to/where/you/ve/put/chromedriver.exe");
ChromeDriver driver = new ChromeDriver(caps);
but my tests are written in Ruby. RubyBindings don't talk about this issue http://code.google.com/p/selenium/wiki/RubyBindings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上,错误消息略有错误。您不必设置系统属性,但 chromedriver 可执行文件需要在远程计算机(运行服务器的位置)上的 PATH 中可用。
如果您想将路径指定为属性,可以在启动服务器时执行此操作,例如:
Actually the error message is slightly wrong. You don't have to set the system property, but the chromedriver executable needs to be available in the PATH on the remote machine (where the server is running).
If you want to specify the path as a property, you can do that when you launch the server, e.g.:
您必须在测试代码中设置 cromedriver.exe 的路径。它类似于
Java,
我也在使用基于 Java 的测试,所以我无法为您提供 Ruby 的确切示例。但基本上你必须告诉你的 Ruby 程序 chromedriver.exe 的路径在哪里
You have to set path to your cromedriver.exe inside the code of the test. Its something like
in Java
I am also using Java based tests, so I cannot give you exact example for Ruby. But basically you have to tell your Ruby program where is the path to chromedriver.exe
好吧,伙计们。在帮助下我可以找到答案。一探究竟。
这就是在本地计算机上设置驱动程序的方式:
在
会是这样的
运行服务器的远程计算机上,在从本地计算机运行测试后,
。祝你好运!
Okay, guys. With the help I could find the answer. Check it out.
That is how you set up the driver on your local machine:
where
On the remote machine running the server would be something like this
After run your tests from the local machine.
Best of luck!
我发现所选答案非常具有误导性。我花了大约一个小时才纠正其中的错误。 节点 是应该设置
webdriver.chrome.driver
属性的节点,而不是集线器。因此,所选答案的命令应为:
java -Dwebdriver.chrome.driver=/path/to/driver -jar selenium-server-standalone.jar -role node
I found the selected answer to be very misleading. It took me about an hour to release the mistake in it. The node is the one that should have the
webdriver.chrome.driver
property set, not the hub.Therefore the selected answer's command should instead be:
java -Dwebdriver.chrome.driver=/path/to/driver -jar selenium-server-standalone.jar -role node