如何为 Chrome 构建远程 Webdriver

发布于 2024-11-27 15:03:05 字数 1427 浏览 2 评论 0原文

我正在尝试针对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

波浪屿的海角声 2024-12-04 15:03:05

实际上,错误消息略有错误。您不必设置系统属性,但 chromedriver 可执行文件需要在远程计算机(运行服务器的位置)上的 PATH 中可用。

如果您想将路径指定为属性,可以在启动服务器时执行此操作,例如:

java -Dwebdriver.chrome.driver=/path/to/driver -jar selenium-server-standalone.jar

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.:

java -Dwebdriver.chrome.driver=/path/to/driver -jar selenium-server-standalone.jar
番薯 2024-12-04 15:03:05

您必须在测试代码中设置 cromedriver.exe 的路径。它类似于

System.setproperty();

Java,

我也在使用基于 Java 的测试,所以我无法为您提供 Ruby 的确切示例。但基本上你必须告诉你的 Ruby 程序 chromedriver.exe 的路径在哪里

You have to set path to your cromedriver.exe inside the code of the test. Its something like

System.setproperty();

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

夜深人未静 2024-12-04 15:03:05

好吧,伙计们。在帮助下我可以找到答案。一探究竟。

这就是在本地计算机上设置驱动程序的方式:

    @driver = Selenium::WebDriver.for(:remote, :chrome :url => 'http://' + SELENIUM_HOST + port + webdriver_hub, :desired_capabilities => browser)

browser = ':chrome'
port = ':4444'
webdriver_hub = '/wd/hub'

会是这样的

    java -jar selenium-server-standalone-2.2.0.jar -Dwebdriver.chrome.driver="path/to/where/you/put/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:

    @driver = Selenium::WebDriver.for(:remote, :chrome :url => 'http://' + SELENIUM_HOST + port + webdriver_hub, :desired_capabilities => browser)

where

browser = ':chrome'
port = ':4444'
webdriver_hub = '/wd/hub'

On the remote machine running the server would be something like this

    java -jar selenium-server-standalone-2.2.0.jar -Dwebdriver.chrome.driver="path/to/where/you/put/chromedriver.exe"

After run your tests from the local machine.

Best of luck!

心在旅行 2024-12-04 15:03:05

我发现所选答案非常具有误导性。我花了大约一个小时才纠正其中的错误。 节点 是应该设置 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文