我正在尝试设置远程webdriver以在远程计算机上运行我的测试,因为我的应用程序已部署到我的localhost。使用Selenium RC我使用主机地址来运行这些测试,它运行良好;但是我在使用远程webdriver设置基类时遇到了麻烦。我已经尝试了以下代码,但它没有奏效。顺便说一句,我有selenium测试,我正在迁移到远程webdriver。我试过webdriver工作正常,但无法设置远程webdriver进行远程执行。任何帮助将不胜感激。
public static String base_url = "http://localhost:8084";
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl(base_url);
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.PROXY, proxy);
RemoteWebDriver driver = new RemoteWebDriver(capabilities);
selenium = new WebDriverBackedSelenium(driver, base_url);
示例网格2代码适用于Firefox但在IE9上不起作用
String hubURL = "http://myip:4444/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
//capability.setBrowserName("internet explorer");
//capability.setPlatform("WINDOWS");
//capability.setVersion("9.0.4");
WebDriver driver = new RemoteWebDriver(new URL(hubURL), capability);
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
driver.quit();
虽然我从IE9命令模式中指定了IE,但是当它是IE9时我才收到错误:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : {platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}
Command duration or timeout: 110 milliseconds
Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:23:11'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.38-13-generic', java.version: '1.6.0_26'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:147)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:435)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:135)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:94)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:102)
at com.main.SelTest.main(SelTest.java:25)
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session cannot find : {platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:151)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:81)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
答案 0 :(得分:10)
您必须安装Selenium Server(Hub)并将远程WebDriver注册到它。然后,您的客户将与Hub交谈,Hub将找到匹配的WebDriver来执行您的测试。
您可以查看here了解详情。
答案 1 :(得分:2)
这个问题来自我,因为我正在使用selenium-server-standalone-2.32.0运行服务器,并且客户端使用selenium-server-standalone-2.37.0注册。当我同时制作了两个selenium- server-standalone-2.32.0并运行然后一切正常
答案 2 :(得分:0)
默认情况下,InternetExplorerDriver侦听端口&#34; 5555&#34;。改变你的huburl以匹配它。你可以在cmd框窗口上查看确认。
答案 3 :(得分:0)
这就是我摆脱错误的方法:
WebDriverException:转发新会话时出错无法找到: {platform = WINDOWS,ensureCleanSession = true,browserName = internet explorer,version = 11}
在nodeconfig.json中,版本必须是字符串,而不是整数。
因此,不要使用"version": 11
使用"version": "11"
(请注意双引号)。
RemoteWebDriver的工作nodecondig.json文件的完整示例:
{
"capabilities":
[
{
"platform": "WIN8_1",
"browserName": "internet explorer",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
"version": "11"
}
,{
"platform": "WIN7",
"browserName": "chrome",
"maxInstances": 4,
"seleniumProtocol": "WebDriver"
"version": "40"
}
,{
"platform": "LINUX",
"browserName": "firefox",
"maxInstances": 4,
"seleniumProtocol": "WebDriver"
"version": "33"
}
],
"configuration":
{
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 3,
"port": 5555,
"host": ip,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": {your-ip-address}
}
}
答案 4 :(得分:0)
-jar selenium-server-standalone-2.44.0.jar -role hub
Java -jar selenium-server-standalone-2.44.0.jar -role webdriver -hub http://HubmachineIPAddress:4444/grid/register -port 5566
还有一件事是,每当我们使用Internet Explore或Google Chrome时,我们都需要设置:System.setProperty("webdriver.ie.driver",path);