java - Selenium RemoteWebDriver UnreachableBrowserException 与边缘

标签 java maven selenium microsoft-edge remotewebdriver

您好,我一直在使用 Maven 和 TestNG 框架开发一个副项目。到目前为止,我的代码在 WebDriver 实例(Chrome、Firefox、Edge)上运行良好,但在尝试使用 Edge 设置 RemoteWebDriver 时,我不断遇到错误。以下是我设置驱动程序类(实现 WebDriver 类)的方法:(显示构造函数部分,通过 RemoteWebDriver 初始化驱动程序:

编辑:

 public Driver (String browserName) {
    this.browserName = browserName;
    ....

    if(browserName.equalsIgnoreCase("edge")) {
        System.setProperty("webdriver.edge.driver","./resources/webdrivers/MicrosoftWebDriver.exe");
        DesiredCapabilities browser = DesiredCapabilities.edge();
        browser.setPlatform(Platform.WIN10);
        try {
            this.driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), browser);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        js = (JavascriptExecutor) driver;
        bugCapture = (TakesScreenshot)driver;
        testFailDir = newFailCapDir();
    }

当使用 mvn 运行代码并设置 -Dbrowser=edge 时,这是我收到的错误:

  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: '3.7.1', revision: '8a0099a', time: '2017-11-
  06T21:01:39.354Z'
  System info: host: 'LAPTOP-L1BFDSGL', ip: '10.0.0.11', os.name: 'Windows 
  10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
  Driver info: driver.version: Driver
  Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 
  localhost:17556 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: 
  Connection refused: connect
  Caused by: java.net.ConnectException: Connection refused: connect

经过一些研究,我认为问题是我没有 Selenium-server-standalone jar 文件,它似乎调用了 Selenium jar 文件的 Maven 依赖项。我在这个网站和其他网站上四处寻找解决方案,但我仍然遇到同样的错误。是否有我丢失的文件或 RemoteWebDriver 可以与 Edge 驱动程序一起应用?

在这种情况下,任何建议都会有所帮助。 谢谢。

更新 @DebanjanB 的请求,我使用的集线器是在声明期间。经过一些研究后,我没有意识到我不必激活集线器或节点。 (可能是我收到无法访问的异​​常的原因。)我还检查了我是否可以设置集线器和节点(我使用端口 -5555 作为节点角色)。我在单独的 cmd 提示符中用于 Hub 和 Node 的命令:

java -jar selenium-server-standalone-3.10.0.jar -role hub 

java -jar selenium-server-standalone-3.10.0.jar -role node -hub 
http://localhost:4444/grid/register -port 5555

我还更新了我的 Maven 依赖项以独立包含到 Selenium 服务器中。 我为测试运行的专家是:

mvn test -Dbrowser=edge -Dgroups=<specified group> 

当我在运行集线器的情况下运行时,我遇到了这个异常错误:

  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: '3.10.0', revision: '176b4a9', time: '2018-03-
  02T19:03:16.397Z'
  System info: host: 'LAPTOP-L1BFDSGL', ip: '10.0.0.11', os.name: 'Windows 
  10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
  Driver info: driver.version: Driver
 Caused by: java.net.ConnectException: Failed to connect to /10.0.0.11:4444
 Caused by: java.net.ConnectException: Connection refused: connect

在失败之前我看到了这条信息: 2018 年 3 月 9 日下午 7:05:25 org.openqa.selenium.remote.DesiredCapabilities 边缘 信息:首选使用 new EdgeOptions() DesiredCapabilities.edge() //关于测试用例失败并跳过的错误

@DebanjanB 如果您需要更多说明,请告诉我。

更新: 我设法让我的 Remote Webdriver 使用 Edge 工作。我不得不提到我在设置集线器后注册节点时要使用的 Dwebdriver。

注册我的节点:

java -Dwebdriver.edge.driver=MicrosoftWebDriver.exe -jar selenium-server-standalone-3.10.0.jar -role node -hub http://localhost:4444/grid/register -端口 5555

(我还为路径添加了物理驱动程序,因为在本地驱动程序上运行时,我将它们放在不同的路径中。)

在我的驱动程序类中(我必须将我的 URL 设置为我的节点而不是我的集线器):

System.setProperty("webdriver.edge.driver","./resources/webdrivers/MicrosoftWebDriver.exe");
                DesiredCapabilities browser = DesiredCapabilities.edge();
                try {
                    driver = new RemoteWebDriver(new URL("http://10.0.0.19:5555/wd/hub"), browser);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }

现在,当我毫无问题地运行 edge 命令时。 :)

最佳答案

错误提示如下:

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.

错误似乎是从行中出来的:

browser.setBrowserName(DesiredCapabilities.edge().getBrowserName());

根据您的代码块,browserDesiredCapabilities 类的一个实例,并且根据 setBrowserName() 的文档方法定义为:

public void setBrowserName(java.lang.String browserName)

edge()方法来自 DesiredCapabilities类帮助我们转换 DesiredCapabilities 对象,但不包含任何方法,例如getBrowserName() 本身。所以下面的表达式会引发错误:

DesiredCapabilities.edge().getBrowserName()

根据 Selenium v​​3.10.0 的当前版本,使用 chrome()firefox( )internetExplorer()edge() 会自动设置 BrowserName 并且不需要明确提及。


更新

您需要发送正确的命令来启动 Selenium Grid HubSelenium Grid Node

关于java - Selenium RemoteWebDriver UnreachableBrowserException 与边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49201395/

相关文章:

java - 在哪里可以找到我的 Maven 项目结构中的 UML 图文件?

ruby-on-rails - Rails RSpec 意外警报打开

java - 如何在android中获取Linkedin个人资料的连接

Java - 避免代码中的长 SQL 查询

java - 如何将面向对象的结构映射到表单字段?

maven - 将所有定义的 Maven 项目属性导出到文件?

java - 命令行上的 mvn -version 显示不同版本的 Java

JavaFX 按钮在第一次单击时没有响应

selenium - 如何在chromedriver中关闭w3c以解决错误未知命令:在W3C中无法调用非W3C标准命令

c# - Selenium 测试项目 C# 未运行 Chrome