Ian Shirley
Ian Shirley

Reputation: 113

How can I run the same test on multiple threads in parallel using Selenium in C#?

Essentially I have 1 test that I want to run on multiple threads at the same time. Currently the only was I have found to do it is to rewrite the test for every thread I want to run so if I want it 10 run 10 times in parallel I have to write 10 tests.

I'm trying to do some minor load testing on a website by using selenium and C# to open multiple instances and attempt to fill in a form. I'm also trying to test race conditions for when the sign-ups are full

[TestFixture]
[Parallelizable]
class TournamentPageScript1
{
    public static IWebDriver driver = new ChromeDriver();

    public static IWebDriver getDriverInstance()
    {
        return driver;
    }

    [SetUp]
    public void initialize()
    {
        driver.Navigate().GoToUrl("https://mywebsite.com");            
    }

    [Test]
    public void validateTournamentPage001()
    {
        //do some stuff
    }

    [TearDown]
    public void tearDown()
    {
        driver.Close();
    }
}
[TestFixture]
[Parallelizable]
class TournamentPageScript2
{
    public static IWebDriver driver = new ChromeDriver();

    public static IWebDriver getDriverInstance()
    {
        return driver;
    }

    [SetUp]
    public void initialize()
    {
        driver.Navigate().GoToUrl("https://mywebsite.com");            
    }

    [Test]
    public void validateTournamentPage002()
    {
        //do some stuff
    }

    [TearDown]
    public void tearDown()
    {
        driver.Close();
    }
}

I want to only have to write the test 1 time and have the Selenium repeat the test in parallel over multiple threads.

Upvotes: 2

Views: 1604

Answers (1)

Shm
Shm

Reputation: 73

Yes, Selenium works well on multiple threads. However if you are trying to get Selenium to submit a form at exactly the same time you will have to have a fast enough processor to run all the threads 'at the same time' which might be difficult since Selenium is a bit heavy. So, in short, multiple instances of selenium work well at the same time but you will have to see if you can practically achieve the speed for your situation.

related: C# multithreading

Upvotes: 1

Related Questions