Selenium RemoteWebDriver c# - System.InvalidOperationException
Asked Answered
M

3

11

I have a sample UI test project using v3.4.0 of Selenium.WebDriver.

Everything works fine when I run the tests against a local driver but I want to get things working using Selenium Grid 2.

As soon as I try to instantiate a new RemoteWebDriver I get an exception with little detail.

Driver = new RemoteWebDriver(new Uri(GridUrl), Capabilities);     

Note: GridUrl is "http://localhost:4444/wd/hub"

Throws a System.InvalidOperationException with StackTrace as follows:

   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
   at xxxx.Ui.Tests.SeleniumTests.TestInitialize() in C:\Users\xxxx\Documents\Visual Studio 2015\Projects\xxxx.Ui.Tests\xxxx.Tests\PersonTests.cs:line 38

Hub configuration

I have v3.4.0 of the hub running locally with the following configuration:

{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher":"org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

Hub started with:

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

This has come up OK and looks to be running. working hub console

Node configuration

I have tried a number of nodes (chromedriver.exe, IEDriverServer.exe and geckodrvier.exe). None of these work with the RemoteWebDriver. All of them are in a directory that has been added to my system PATH variable.

Chrome config

{
  "capabilities":
  [
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": 5556,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

Node started with:

java -jar selenium-server-standalone-3.4.0.jar -role node -nodeConfig chromeNodeConfig.json

The other node configs are largely the same except for the different browser names and ports.

Once all nodes are started, the console looks as follows: console with nodes running

I'm not able to get much from the exception. Is it a versioning issue of the drivers I have? I have tried customising my DesiredCapabilities to ensure I'm matching those in the node config. All of that looks fine.


Update

As requested I'm adding a bit more detail as to how I'm trying to launch a browser. None of the browsers work with the RemoteWebDriver whereas they do with the local drivers. Showing the Chrome example - only difference between each is regarding the Capabilities that I'm passing in to the base class constructor.

In my test class

[TestClass]
public class PersonTests : PersonTestBase
{
    public PersonTests() 
        : base(DesiredCapabilities.Chrome())
    {
    }

    [TestCategory("Chrome")]
    [TestMethod]
    public void Chrome_ShouldCreatePlacement()
    {
        this.ShouldCreatePerson();
    }        
}

In my base class I am doing the following

public abstract class PersonTestBase
{
    protected IWebDriver Driver;
    protected ICapabilities Capabilities;
    protected string TargetUrl;
    protected string GridUrl;

    protected PersonTests(ICapabilities capabilities)
    {
        this.Capabilities = capabilities;
    }

    [TestInitialize]
    public void TestInitialize()
    {
        TargetUrl = "http://urlOfMyWebsite";
        GridUrl = "http://localhost:4444/wd/hub"

        Driver = new RemoteWebDriver(new Uri(GridUrl), Capabilities);            
    }

    [TestCleanup]
    public void TestCleanup()
    {
        Driver.Quit();
    }

    protected void ShouldCreatePerson()
    {
        Driver.Navigate().GoToUrl(TargetUrl);

        //rest of test code ommitted
    }
}
Melvin answered 3/5, 2017 at 16:16 Comment(4)
Might want to check task manager and make sure you don't have a bunch of rogue browser driver instances still running. This can happen when debugging locally. This has caused a number of problems for us.Roughage
Thanks for the suggestion. I'll have a look tomorrow!Melvin
What browser are you trying to launch? Can you provide more code around how you're doing that?Collagen
I've added the update as requested. @Roughage - thanks for the suggestion. I had a number of ChromeDriver processes running but restarted my machine and re-ran the test and still the same exception.Melvin
M
11

Downgrade to 3.3.0 until this issue gets resolved and a new release of Selenium Standalone Server is available (Recommended solution)

Or

  1. Download the Solution
  2. Comment this line
  3. Build dotnet language bindings
    • Open command window in root directory
    • Run go //dotnet:release
    • And reference the binaries built in {root}/build/dotnet/dist

Note: This workaround does NOT fix anything! It ignores the piece of selenium grid code that causes failure.

Another note: Be aware that upgrading to Selenium 3.4 may require upgrading webdrivers as well

Marius answered 5/5, 2017 at 19:47 Comment(2)
Excellent. I've downgraded Selenium.WebDriver and Selenium.Support to v3.3.0. This now works. Thanks very much - been searching for a while with no progress!Melvin
@StephenCavender I am not sure about the C# binding of Selenium Grid 3.4.0 but for my Java bindings it executes perfectly with default settings.Molokai
L
2

V3.5.1 Fixes this issue.

Upgrade your Selenium NuGET package using NuGET manager & your selenium-standalone jar.

Lance answered 16/8, 2017 at 5:57 Comment(0)
B
0

Downgrading to 3.3.0 as it was suggested by Stephen may cause known issue. Try downgrading to v3.3.1 instead.

You can get the v3.3.1 from here: http://selenium-release.storage.googleapis.com/index.html?path=3.3/

Biotype answered 12/6, 2017 at 1:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.