Giorgi Tediashvili
Giorgi Tediashvili

Reputation: 13

C# Selenium - Execute tests in parallel

i want to execute multiple tests in parallel, here is some code. i'm using Post method but this doesn't works, can anyone help me?

namespace BusinessLayer.BusinessLogic.UI
{
    [TestFixture]
    [Parallelizable]
    public class nunitlayer : BaseLayer
    {
        [Test]
        public static void test1(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.LoginTest(driver, wait, urlTypeId);
            }
            [Test]
            public static void test2(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.ArmenianLoginTest(driver, wait, urlTypeId);
            }
        }
 }



case (int)TestType.nunit:
                        nunitlayer.test1(chrome.driver, chrome.wait, urlTypeId);
                        break;

Upvotes: 0

Views: 4981

Answers (1)

Charlie
Charlie

Reputation: 13681

You have [Parallelizable] on your test fixture class, nunitlayer. That means it will run in parallel with other fixtures that also have [Parallelizable].

If you want the tests inside nunitlayer to run in parallel with one another, you should do one of the following:

  1. Put [Parallelizable] on each of the tests instead of on the fixture...

    namespace BusinessLayer.BusinessLogic.UI
    {
        [TestFixture]
        public class nunitlayer : BaseLayer
        {
            [Parallelizable]
            [Test]
            public static void test1(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.LoginTest(driver, wait, urlTypeId);
            }
    
            [Test]
            [Parallelizable]
            public static void test2(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.ArmenianLoginTest(driver, wait, urlTypeId);
            }
        }
     }
    
  2. Put [Parallelizable(ParallelScope.Children)] on the fixture...

    namespace BusinessLayer.BusinessLogic.UI
    {
        [TestFixture]
        [Parallelizable(ParallelScope.Children)]
        public class nunitlayer : BaseLayer
        {
            [Test]
            public static void test1(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.LoginTest(driver, wait, urlTypeId);
            }
    
            [Test]
            public static void test2(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.ArmenianLoginTest(driver, wait, urlTypeId);
            }
        }
    }
    

Either approach will make the tests run in parallel, but it doesn't guarantee they will work. You have not shown where your data for the test method arguments come from. You show a case statement, where the nunit test appears to be called but this is not how NUnit tests are normally run and we don't know if each test is getting (for example) a unique driver. IOW, there are lots of other things that may go wrong and I suspect there's a lot of info about how the tests are run that you have not yet shared.

Upvotes: 3

Related Questions