简体   繁体   中英

Nunit Selenium Parallel Tests with Values

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM