简体   繁体   中英

Selenium WebDriver All Parallel Tests Execute In A Single Window - TestNG - Java

I am new to parallel execution and am trying to figure out why all 3 of my tests are trying to execute in a single window at the same time even though 3 separate windows are opened.

I have 3 nodes running all with Chrome and maxInstance and maxSession set to 1, so each node should get receive 1 class to run, which it appears they do as you can see in this screenshot: 在此处输入图片说明

This is what my test.xml file looks like:

<suite name="Round Trip Suite" parllel="tests" thread-count="3">

 <test name="Round Trip Matrix" preserve-order="true" parallel="classes" thread-count="3">

 <classes>
  <class name ="roundTripMatrix.VerifyNewOrder"/>
  <class name ="roundTripMatrix.DeclineAndAccept"/>
  <class name ="roundTripMatrix.OrderOwnership"/>
 </classes>

 </test>

</suite>

I am initializing the RemoteWebDriver in the @BeforeClass annotation like this:

if (browser.equals("Chrome"))
{
    String chromeDriver = "";
    if (os.equals("Windows"))
    {
        chromeDriver = userDir.replace(project, "drivers\\chromedriver.exe");
    }
    else
    {
        chromeDriver = userDir.replace(project, "drivers/chromedriver");
    }
    System.setProperty("webdriver.chrome.driver", chromeDriver);

    if (useSeleniumGrid.equals("true"))
    {
        // Access Grid
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        capability.setBrowserName("chrome");
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
    }
    else
    {
        driver = new ChromeDriver();
    }

} // end if for Chrome browser

UPDATE:

I have figured out the reason only one window was receiving the commands is because I wasn't using a threadlocal driver. My problem now is it fails at weird spots in all the windows, even though they were working while running individually previously.

Your test.xml has error. Could you try it:

<suite name="Round Trip Suite" parallel="classes" thread-count="3">
 <test name="Round Trip Matrix">
   <classes>
     <class name ="roundTripMatrix.VerifyNewOrder"/>
     <class name ="roundTripMatrix.DeclineAndAccept"/>
     <class name ="roundTripMatrix.OrderOwnership"/>
   </classes>
 </test>
</suite>

More information: enter link description here

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