4

I'm trying to run the same nunit Test method with different values in parallel. However the second test seems to fail (i think it's trying to use the first instance of the browser;

This is the test;

 namespace AutomationProject.Login_Test_Cases
{
    [TestFixture]
    [Parallelizable(ParallelScope.Children)]
    class Login_Test_Cases: BaseTest
    {

        [Test]

        public void LoginPar([Values("skynet" ,"skynet2")] string username)
        {

            lg.Log_In(username, "password");
            }
        }
}

This is the baseTest where the browser is set up;

namespace AutomationProject.BaseClasses
{
    public class BaseTest 

    {

        public Log_In_Methods lg;
        public IWebDriver driver;


       [SetUp]
        public void StartBrowser()
        {

            System.Diagnostics.Trace.AutoFlush = true;

            ChromeOptions options = new ChromeOptions();
            options.AddAdditionalCapability("useAutomationExtension", false);
            driver = new ChromeDriver(//path to chrome driver);

            lg = new Log_In_Methods(driver);

            driver.Manage().Window.Maximize();
            driver.Url = "http://login-test.com";


        }

I've also added [assembly: Parallelizable(ParallelScope.Children)] [assembly: LevelOfParallelism(2)] to AssemblyInfo

The second test always seems to fail (the browser does not even get the url)

I can run different classes and tests in parallel with no issues.

Does anyone know if it's possible to run the same test method in parallel with different values?

2
  • call StartBrowser() method into Login_Test_Cases class Commented Jul 18, 2018 at 12:01
  • thanks, but no luck I'm afraid. I tried removing the [SetUp] annotation and calling StartBrowser() but the second test still fails as above. Commented Jul 18, 2018 at 12:38

1 Answer 1

2

Does anyone know if it's possible to run the same test method in parallel with different values?

This is absolutely possible. The issue here is that both tests run in parallel on a single instance of the BaseTest class, and thus you only have a lg field which both tests are trying to create/use simultaneously.

Being able to run the two separate tests with two separate BaseTest objects is an open feature request, see here: https://github.com/nunit/nunit/issues/2574

In the meantime, if you were to include your [SetUp] logic within your test method and use local variables, what you're trying to do should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, adding the local variables (creating the driver and pages) in the [Test] logic worked. Sorry I don't have enough rep to upvote this aswell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.