Selenium RemoteWebDriver UnreachableBrowserException与Edge [英] Selenium RemoteWebDriver UnreachableBrowserException with Edge

查看:106
本文介绍了Selenium RemoteWebDriver UnreachableBrowserException与Edge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Maven和TestNG Framework进行辅助项目.到目前为止,我的代码在WebDriver实例(Chrome,Firefox,Edge)上运行良好,但是在尝试使用Edge设置RemoteWebDriver时,我总是遇到错误.这是我设置驱动程序类(实现WebDriver类)的方式:(显示通过RemoteWebDriver初始化驱动程序的构造器部分:

Hi I've been working on a side-project using Maven and a TestNG Framework. So far my code works well with WebDriver instances (Chrome, Firefox, Edge), but I keep getting errors when attempting to set up a RemoteWebDriver with Edge. Here is how I have my Driver class(Implementing WebDriver Class) set up: (Showing the constructor portion with initializing Driver through 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时,这是我收到的错误:

When running the code with mvn and setting -Dbrowser=edge, this is the error I receive:

  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服务器独立的jar文件,似乎调用了Selenium jar文件的Maven依赖关系.我在该站点和其他站点上四处寻找可以解决我的问题的方法,但是我仍然遇到相同的错误.是否缺少我的文件,或者可以将EdgeWebDriver与Edge驱动程序一起应用?

After some research, I thought the problem was that I didn't have the Selenium-server-standalone jar file, it seems to call on the Maven Dependencies of Selenium jar files. I've looked around on this site and others to find the solution to my problem, but I'm still getting the same error. Is there a file I'm missing or can RemoteWebDriver be applied with Edge driver?

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

Any advice would help in this situation. Thanks.

更新@DebanjanB的请求,我使用的集线器是在声明期间.经过一番研究,我没有意识到我不必具有集线器或节点处于活动状态.(这可能是为什么我无法到达异常的原因.)我还检查了我是否可以设置集线器和节点(我将端口-5555用于节点角色).我在单独的cmd提示符下用于集线器和节点的命令:

Update @DebanjanB's request, The hub I used was during the declaration. After some research I didn't realize that I didn't have to have a hub or node active. (Probably why I was getting unreachable exception.) I also checked that I could set up a hub and node(I used port -5555 for node role). Commands I used for Hub and Node in separate cmd prompts:

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是:

I also updated my maven dependencies to include to Selenium server standalone. The maven I was running for my test was:

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

运行集线器时,出现此异常错误:

When I ran with the hub running I was getting this exception error:

  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 PM org.openqa.selenium.remote.DesiredCapabilities边缘信息:首选使用 new EdgeOptions() DesiredCapabilities.edge()//关于测试用例的错误失败并被跳过

Before the failure I saw this message: Mar 09, 2018 7:05:25 PM org.openqa.selenium.remote.DesiredCapabilities edge INFO: Using new EdgeOptions() is preferred to DesiredCapabilities.edge() //Error about test cases failed and skipped

@DebanjanB让我知道是否需要更多说明.

@DebanjanB let me know if you need more clarification.

更新:我设法使我的远程Webdriver使用Edge正常工作.我不得不提到在设置集线器后注册Node时要使用的Dwebdriver.

Update: I managed to get my Remote Webdriver working using Edge. I had to mention the Dwebdriver I was going to use when registering my Node after setting up my hub.

注册我的节点:

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

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

(而且我还为该路径添加了物理驱动程序,因为在本地驱动程序上运行时,我将它们放置在其他路径中.)

(And I had add the physical driver as well for the path since when running on local drivers, I placed them in a different path.)

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

In my Driver class (I had to set my URL to my node instead of my hub):

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

现在,当我为边缘运行命令而没有问题时.:)

Now when I run the command for edge without issue. :)

推荐答案

该错误为我们提供了如下提示:

The error gives us some hint as follows :

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

根据您的代码块,浏览器 DesiredCapabilities 类的实例,并且根据

As per your code block, browser is an instance of DesiredCapabilities Class and as per the documentation of setBrowserName() method it is defined as :

public void setBrowserName(java.lang.String browserName)

edge() 方法"rel =" nofollow noreferrer> DesiredCapabilities 类可帮助我们转换 DesiredCapabilities 对象,但不包含任何方法,例如 getBrowserName()这样.因此,以下表达式会引发错误:

The edge() method from DesiredCapabilities Class helps us to cast the DesiredCapabilities object but doesn't contain any method e.g. getBrowserName() as such. So the following expression raises an error :

DesiredCapabilities.edge().getBrowserName()

根据当前版本的 Selenium v​​3.10.0 ,使用 chrome() firefox() internetExplorer() edge()将自动设置 BrowserName ,无需明确提及.

As per the current release of Selenium v3.10.0, casting the DesiredCapabilities object with either chrome(), firefox(), internetExplorer() or edge() would automatically set the BrowserName and won't be needed to be explicitly mentioned.

您需要发送适当的命令来启动 Selenium Grid Hub Selenium Grid Node .

You need to send proper commands to start the Selenium Grid Hub and Selenium Grid Node.

  • 对于错误,您看到的是 org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话检查讨论

有关完整的工作流程,请查看讨论

For a complete workflow check the discussion IE11 test runs if specified direct node ip but fails when grid hub url specified

这篇关于Selenium RemoteWebDriver UnreachableBrowserException与Edge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆