Search code examples
javamavenseleniummicrosoft-edgeremotewebdriver

Selenium RemoteWebDriver UnreachableBrowserException with Edge


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:

Edits:

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

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

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.

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

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

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 let me know if you need more clarification.

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.

Registering my Node:

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.)

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. :)


Solution

  • 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.
    

    The error seems to be coming out of the line :

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

    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)
    

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

    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.


    Update

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