Search code examples
c#selenium-webdriverautomationnunit

How can I run multiple test fixtures in parallel using Selenium/NUnit?


I have a bit of a problem. I am working on an automation project and I'm trying to execute a test on multiple browsers in parallel.
I have these 2 classes:

[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(EdgeDriver))]
[TestFixture(typeof(FirefoxDriver))]
public class BaseTest<TWebDriver> where TWebDriver : IWebDriver, new()
{
    protected IWebDriver _driver;

    [SetUp]
    protected void SetUp()
    {
        _driver = new TWebDriver();
    }

    [TearDown]
    protected void TearDown()
    {
        _driver?.Close();
    }
}

public class GoogleTest<TWebDriver> : BaseTest<TWebDriver> where TWebDriver : IWebDriver, new()
{
    [Test]
    public void NavigateToGoogle()
    {
        // Navigate
        _driver.Manage().Window.Maximize();
        _driver.Navigate().GoToUrl("http://www.google.com/");
    }
}

And I know I should add [Parallelizable] somewhere... but don't know where. I tried both placing it above the BaseTest class and above NavigateToGoogle method but it doesn't work either way. Does somebody have any idea? Or maybe I do something wrong the way I created these classes?
Thanks!


Solution

  • By default [Parallelizable] uses ParallelScope.Self as the scope. This means that the test will be able to run in parallel with other tests. Since there's only 1 test, it will execute synchronously.

    Try changing the scope to Fixtures:

    [TestFixture(typeof(ChromeDriver))]
    [TestFixture(typeof(EdgeDriver))]
    [TestFixture(typeof(FirefoxDriver))]
    [Parallelizable(ParallelScope.Fixtures)]
    

    You can see the different scopes and their meaning here: https://docs.nunit.org/articles/nunit/writing-tests/attributes/parallelizable.html