【问题标题】:Selenium RemoteWebDriver UnreachableBrowserException with EdgeSelenium RemoteWebDriver UnreachableBrowserException with Edge
【发布时间】:2018-03-09 20:06:08
【问题描述】:

您好,我一直在使用 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 Dependencies。我在这个网站和其他网站上四处寻找我的问题的解决方案,但我仍然遇到同样的错误。是否有我丢失的文件或 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 服务器。 我为测试运行的 maven 是:

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 如果您需要更多说明,请告诉我。

更新: 我设法让我的远程 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 -port 5555

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

在我的 Driver 类中(我必须将我的 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();
                }

现在当我运行边缘命令时没有问题。 :)

【问题讨论】:

    标签: java maven selenium microsoft-edge remotewebdriver


    【解决方案1】:

    这个错误给了我们一些提示如下:

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

    根据您的代码块,browser 是 DesiredCapabilities 类的一个实例,根据 setBrowserName() 方法的文档,它被定义为:

    public void setBrowserName(java.lang.String browserName)
    

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

    DesiredCapabilities.edge().getBrowserName()
    

    根据当前版本的 Selenium v​​3.10.0,使用 chrome()、firefox()、internetExplorer() 或 edge() 投射 DesiredCapabilities 对象将自动设置BrowserName,不需要明确提及。


    更新

    您需要发送正确的命令来启动 Selenium Grid Hub 和 Selenium Grid 节点。

    【讨论】:

    • 我删除了行 browser.setBrowserName(DesiredCapabilities.edge().getBrowserName()); ,但我仍然遇到与以前相同的错误。
    • 你能用 Hub & Node 启动命令更新问题吗?
    • 我根据您的要求更新了我的信息,请随时了解更多信息。
    • 您提供的链接很有帮助。设置好 Dwebdriver 后,看起来我的情况与 Vadium 类似。我已经用解决方案更新了我的问题。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2018-11-30
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多