我有这个问题。在不同的计算机上,我启动 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 和端口上访问控制台。我不知道出了什么问题。一切都值得赞赏,谢谢
** 编辑 **
Iried 在另一台计算机上运行它,我遇到了同样的错误。小调试向我展示了这条消息:
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?