Selenium Grid不会在另一台计算机上运行Chrome

时间:2012-04-04 08:41:09

标签: selenium webdriver selenium-grid selenium-chromedriver

我有这个问题。在不同的计算机上,我启动HUB和NODE,然后在我初始化Google Chrome的地方运行我的测试:

 Selenium selenium = new DefaultSelenium("localhost", 4444, *googlechrome, "http://www.google.com");
 DesiredCapabilities capabilities = DesiredCapabilities.chrome();
 capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
 WebDriver  driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

我的计算机上运行正常 - Chrome启动并执行脚本。但是,如果我的朋友尝试完全相同,她会收到此错误:

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_29'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:435)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:139)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:94)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:102)
    at com.deutscheboerse.test.PerfTests.<init>(PerfTests.java:52)
    at com.deutscheboerse.test.EUAStressTest.myTest(EUAStressTest.java:37)
    at com.deutscheboerse.test.EUAStressTest.main(EUAStressTest.java:60)
Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 4422; received: 3743
    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:197)
    at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:105)
    at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:152)
    at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:237)
    at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:186)
    at org.apache.http.util.EntityUtils.consume(EntityUtils.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.<init> HttpCommandExecutor.java:399)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:287)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:415)
    ... 6 more

到目前为止,我发现的唯一区别是,她的中心正在监听http://10.10.190.134:5555我正在监听http://10.131.7.44:5555,但两者都可以在同一IP和端口上访问控制台。我没有任何线索什么是错的。感谢所有的一切,谢谢

**编辑**

无法在另一台计算机上运行它并且我遇到了同样的错误。很少的调试显示了这条消息:

11:04:01.899 WARN - Exception: 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/chromedriver/downloads/list

所以,在Selenium Grid中设置Chrome之前,我需要这样做:

System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");

我试图这样做并且无法运行Chrome ...仍然需要任何帮助

EDID2 这就是我如何设置属性:

File file = new File("lib/chromedriver.exe");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());

我正在使用这种方法,因为我需要在更多计算机上运行它,而JAR文件可以有不同的位置。

顺便说一下,在角色节点中的Selenium Grid窗口中可以找到警告。我在想,如果还有其他切换器。到目前为止,我正在运行这些命令:

java -jar lib//selenium-server-standalone-2.20.0.jar -role hub
java -jar lib/selenium-server-standalone-2.20.0.jar -role node  -hub http://localhost:4444/grid/register -maxSession 12

and then my JAR. The exception is in window with the NODE. Is there any switcher?

2 个答案:

答案 0 :(得分:11)

经过一天的搜索,我有了解决方案。一切都在于如何启动节点。首先,做通常的事情:

java -jar lib/selenium-server-standalone-2.20.0.jar -role hub

然后像这样启动节点:

java -jar lib/selenium-server-standalone-2.20.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver=lib\chromedriver.exe 

更具体地说:您必须使用参数browser启动NODE并添加-D参数,指定ChromeDriver的完整路径

我非常感谢John Naegle在这里回答了关于Internet Explorer的类似问题 - 请参阅here

答案 1 :(得分:1)

这很有趣,但是webdriver无法解析dns,http://localhost:4444/ 我编辑了我的主机文件,未注释的行:

127.0.0.1 localhost

已经完成了。