2

I am working on setting up a distributed testing environment and am running in to an interesting issue. When running tests in parallel the tests seem to get routed to the correct nodes and execute to a point however the hub seems to be sending the browser close and session close commands for all tests being run in in parallel to a single node instead of one to each node that is running as should occur.

Some Background:

I have developed a testing framework to test one of our organizations applications using C#, the C# selenium language bindings, NUnit, and Selenium Grid. My tests are rather simple right now (I simply open up a browser and navigate to Google) to verify the functionality of my Selenium Grid.

The issue I am running in to only occurs when I run tests in parallel. When executing my tests in a single file fashion they appear to get sent to the hub and then are relegated to the proper nodes and run successfully.

I am achieving parallel execution of my tests by applying the [Parallelize] attribute at the [TestFixture] level of my classes.

My environment is currently one Windows 2012 R2 server running Selenium Server 3.0.1 in hub mode, the same server running Selenium Server 3.0.1 in Node mode, and one MacBook Air running Selenium Server 3.0.1 in node mode.

The configuration for my Windows node is as follows:

{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "internet explorer",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "maxSession": 5,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "hub": "REDACTED",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

My Windows hub configuration is as follows:

{
  "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
}

An example of my tests being run are as follows:

namespace BSPTests
{
    [TestFixture]
    [Parallelizable]
    public class ParallelTestsTwo
    {
        [Test]
        public void TestMethod2()
        {
            Driver.Initialize("safari", "MAC", "HUB_URL_HERE");
            Debug.GoTo("http://www.google.com");
            Driver.Close();
        }
    }
}

My Driver.Close() code is as follows: (Driver is a method that wraps my current instance of the RemoteWebDriver)

public static void Close()
{
    // Close the currently open browser and dispose of the currently open instance
    Instance.Close();
    Instance.Dispose();
}

Does anyone have any advice as to how to make my grid function properly?

4
  • 1
    One of the best questions I have seen in a long time. If I could, I would give you 2 up-votes. Welcome to the site! I will look into this and see if I can assist. I would recommend removing/editing your endpoints though. Is driver a static class by chance?
    – Paul Muir
    Dec 28, 2016 at 17:39
  • 1
    Yes, my driver class is static because I pass it around a lot in my testing framework. I see where that is causing some issues though. A static test class equates to a single test session which would not work well when it comes to running tests in parallel. Dec 28, 2016 at 18:25
  • Are you using the Page Object Model? If not, you can avoid 'passing around' the driver a lot using it by using a single base class with a constructor which is essentially PageFactory.Init(this,driver) and then each class with a Constructor with (IWebDriver driver) :base(driver). If you would like to discuss further I will be in the chat off an on most of today
    – Paul Muir
    Dec 28, 2016 at 18:31
  • Unfortunately I am using the Page Object Model to try and develop a sort of DSL in my testing framework to make it easier for my coworkers to use the framework with limited coding experience. I would greatly appreciate discussing this in chat with you however I'm not sure that I have enough rep yet to use the chat functionality. Dec 28, 2016 at 18:58

1 Answer 1

2

It appears as though you are using a static instance for the close operation. I am not certain of the inner workings of your driver class but it is possible that this is causing the issue.

I would recommend using a non-static object for managing your driver in order to ensure that you are always accessing the same Session.

To do further debugging to determine if the issue is in your code or potentially with the setup, pause the execution of your code in the middle of multiple sessions and make the following requests:

GET method http://WebDriverEndpoint/wd/hub/sessions

This will return the sessions for the WebDriver, copy one of them and then call:

DELETE method http://WebDriverEndpoint/wd/hub/session/{sessionId}/window

Which should close out the corresponding webdriver session.

Information for endpoints can be found in the selenium source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.