Why the tests are not running in Parallel mode using Selenium C# Unit?

341 Views Asked by At

I am trying to run my tests on Parallel mode but it is running sequentially and not parallelly. I found one question link here but the solution provided in the same(Neil and Charlie, both) is also not working for me.

Here is my base class:-

[TestFixtureSource(typeof(TestDataProvider), nameof(TestDataProvider.BrowsersToRunWith))]
[TestFixture]
public class CrossBrowser
{
    public IWebDriver driver;
    public string Browsername { get; }


    public CrossBrowser(string browserName)
    {
        Browsername = browserName;

    }

    [SetUp]
    public void LaunchBrowser()
    {


        if (Browsername.ToLower().Contains("chrome"))
        {
            driver = new ChromeDriver();
        }
        else
        {
            driver = new FirefoxDriver();
        }

    }

TestDataProvider Class:-

class TestDataProvider
{
    internal static IEnumerable BrowsersToRunWith
    {            
        get
        {
           String[] browser = { "Chrome", "FireFox" };
            foreach (string b in browser)
            {
                yield return b;
            }
        }
    }
}

Test Class1:-

[Parallelizable(ParallelScope.Self)
public class UT1 : CrossBrowser
{
    
    public UT1(String browserName) : base(browserName)
    {
        Console.WriteLine("Browser is " + browserName);
    }

    [Test]
    public void OpenGoogle()
    {
        driver.Url = "http://google.com";
        driver.Quit();
    }
        
}

Test Class2:-

[Parallelizable(ParallelScope.Self)]

public class UT2 : CrossBrowser
{
    
    public UT2(String browserName) : base(browserName)
    {
        Console.WriteLine("Browser is " + browserName);
    }

    [Test]
    public void OpenGoogle()
    {
        driver.Url = "http://google.com";
        driver.Quit();
    }
        
}

Test Explorer:-

enter image description here

When I am running all the tests, it is running one by one and not on a parallel mode. Am I missing anything? Please suggest. Thanks

0

There are 0 best solutions below