gpt4 book ai didi

java - 设置 Remote Webdriver 以使用 Java 在远程计算机上运行测试

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:55:10 26 4
gpt4 key购买 nike

我试图设置远程 webdriver 以在远程计算机上运行我的测试,因为我的应用程序已部署到我的本地主机。使用 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);

适用于 firefox 但不适用于 IE9 的示例网格 2 代码

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();

虽然我从节点的命令模式指定了 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)

最佳答案

您必须安装一个 Selenium 服务器(一个集线器)并向其注册您的远程 WebDriver。然后,您的客户端将与 Hub 对话,Hub 将找到匹配的 WebDriver 来执行您的测试。

你可以看看here获取更多信息。

关于java - 设置 Remote Webdriver 以使用 Java 在远程计算机上运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8837875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com