用于RemoteWebDriver的Selenium Grid 2为Chrome浏览器提供了一个例外

时间:2013-04-09 09:10:43

标签: google-chrome selenium remotewebdriver

请参阅我的网格批处理文件。 (我在路径中添加了chrome二进制和chrome驱动程序位置)

如果我使用firefox,我的代码可以正常工作,但对于Chrome和IE,它会抛出下面给出的异常。我相信我错过了一件非常微不足道的事情,但我无法弄清楚。

Batch file

set HERE=C:\Users\Administrator\Downloads
set JAVA_HOME=%HERE%\jdk-7u13-windows-x64
set PATH=%JAVA_HOME%\jre\bin;%JAVA_HOME%\bin;%CHROME_DRIVER_LOC%;%IE_DRIVER_LOC%;%CHROME_BINARY_LOC%;%PATH%;
set SELENIUM_VERSION=2.29.0
set CHROME_VERSION=chromedriver_win_26.0.1383.0
set HUB_URL=http://localhost:4444/grid/register
set CHROME_DRIVER_LOC=C:\Users\Administrator\Downloads\chromedriver_win_26.0.1383.0\chromedriver.exe
set IE_DRIVER_LOC=C:\Users\Adminstrator\Downloads\IEDriverServer_x64_2.31.0\IEDriverServer.exe
set CHROME_BINARY_LOC=C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe
start java -jar selenium-server-standalone-2.29.0.jar -role hub
start java -jar selenium-server-standalone-2.29.0.jar -role node
-Dwebdriver.chrome.driver=%CHROME_DRIVER_LOC% -hub %HUB_URL% -port 5556

My sample code:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
URL url = new URL(“<http://localhost:4444/wd/hub>”);
WebDriver driver = new RemoteWebDriver(url, capabilities);

// And now use this to visit Google
driver.get(“web page”);

Exception I am getting :

Exception in thread “main” org.openqa.selenium.WebDriverException: The path to the driver 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/chromedriver/downloads/list
Command duration or timeout: 608 milliseconds
Build info: version: ’2.29.0′, revision: ’58258c3′, time: ’2013-01-17 22:47:00′
System info: os.name: ‘Windows Server 2008 R2′, os.arch: ‘amd64′, os.version: ’6.1′, java.version: ’1.7.0_13′
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at test.Test.main(Test.java:32)
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see ….

请帮忙!我无法理解我做错了什么。从现在开始,我一直在努力解决这个问题。任何帮助将非常感谢。

Thanks
Sushmita

3 个答案:

答案 0 :(得分:1)

我认为,以下行是罪魁祸首

start java -jar selenium-server-standalone-2.29.0.jar -role node
-Dwebdriver.chrome.driver=%CHROME_DRIVER_LOC% -hub %HUB_URL% -port 5556

使用下面的行并检查它是否正常工作。

start java -Dwebdriver.chrome.driver=%CHROME_DRIVER_LOC% -jar selenium-server-standalone-2.29.0.jar -role webdriver -hub %HUB_URL% -port 5556

答案 1 :(得分:1)

使用Chrome和IE,您需要定义驱动程序可执行文件路径,您可以在此处对文件进行优化: http://code.google.com/p/chromedriver/downloads/listhttp://code.google.com/p/selenium/downloads/list

在创建新的ChromeDriver之前,您需要这样的东西: String chromeDriverPath =“C:\ ChromeDriver.exe”; System.setProperty(“webdriver.chrome.driver”,chromeDriverPath);

答案 2 :(得分:1)

一个非常简单的解决方法是将IEDriverServer和chromedriver可执行文件放在与selenium jar文件相同的文件夹中