1

I am finding issues with the selenium grid and parallel tests, when I execute the tests against the grid with 1 node all tests pass with no issues.

When I add a 2nd node the tests fail, I assume they are falling over one another but I'm not sure what I need to do to prevent this from happening

In my assembly, I have declared

[assembly: Parallelizable(ParallelScope.Fixtures)]

The error on one of the tests is as follows

OpenQA.Selenium.NoSuchElementException : Unable to find element
----> System.InvalidOperationException : Session 
[bda80023962a2441e3c7ae66a75e982e] was terminated due to 
CLIENT_STOPPED_SESSION

Any help will be hugely appreciated

Adding to this to get some help as i am making no progress

I am using the following packages

  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
  <package id="NUnit" version="3.8.1" targetFramework="net452" />
  <package id="NUnit.Console" version="3.0.0" targetFramework="net452" />
  <package id="Selenium.Support" version="3.7.0" targetFramework="net452" />
  <package id="Selenium.WebDriver" version="3.7.0" targetFramework="net452" />
  <package id="SpecFlow" version="2.2.1" targetFramework="net452" />
  <package id="SpecFlow.NUnit" version="2.2.1" targetFramework="net452" />

i have a standard selenium grid setup, with 2 physically separate nodes and when the tests run individually they pass with no issues but when running in parallel both tests fail with different errors

OpenQA.Selenium.WebDriverException : no such session

and

OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element

I am still completely baffled why this is happening.


Adding even more to this I am pretty sure it is due to my lack of coding skill, I think the drivers are getting confused with one another when the tests are running which is why individually they run with no issue.

so I need to try and explain what I have built to see if anyone can help

so I have a Specflow feature file This is linked to a steps class which holds the steps for the tests and nothing else

and I have a General class which I wanted each test to run through so this is responsible for creating the driver and passing it through so I fear this is where I have gone wrong.

at the top of the general class, i create the driver

public static IWebDriver Driver;

Also in the general class, I have a constructor

  public General(IWebDriver driver)
    {
        Driver = driver;
    }

in the general class i have

    [BeforeScenario()]
    public static void BeforeScenario()
    {
        Driver = StartLocalDriver();
    }

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

This I was hoping would create a driver for the test before each scenario

I was hoping this would allow the driver to be assigned individually to each test but i guess the drivers can all still see one another and are getting in each others way.

i was wondering if anyone has a better approach to prevent this from happening

The steps class picks up the driver as I have a using statement at the top of each steps page

using static MoneyUITests.Methods.General;

i fear this might be difficult as the steps are in different files and some are reused for other tests

anyone able to help me with this?

Brian Mitchell
  • 345
  • 3
  • 21

1 Answers1

0

I found that I was making the mistake of making the driver static which means when the steps code when to execute they drivers when hitting the base classes were tripping up over one another.

so I found another stack overflow question that helped me solved my issue

NUnit Specflow how to share a class instance for all tests

This example gets you to use IOC to ensure the correct instance for the driver is being called each time. This allows the tests to run in parallel with one another.

I now have one class with a constructor which spins up the driver.

and in each steps class, I have the following

[Binding]
class MySteps
{
    private readonly SeleniumContext _seleniumContext;

    public MySteps(SeleniumContext seleniumContext)
    {
        _seleniumContext = seleniumContext;
    }

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

It's not the most elegant solution but it seems to work for me

Brian Mitchell
  • 345
  • 3
  • 21