executing 2 test cases in parallel using TestNG.xml file

Viewed 51

I am using TestNG.xml file to perform 2 test cases in parallel. The problem is, whenever I run the .xml file 2 browsers open but the steps get executed only for one of them at the same time which means, if one of the steps is responsible for filling a field with the number "2", only on one browser the field gets filled by "22"!

The .xml file is as follows:

<?xml version = "1.0" encoding = "UTF-8"?>
<suite name = "Suite" parallel = "classes" thread-count = "2">
    <test name = "Test" parallel = "classes">
        <classes>
            <class name = "package1.javas.second" />
            <class name = "package1.javas.first" />
        </classes>
    </test>
</suite>

public class first {

   WebDriver driver = null;


   @BeforeTest
   public void driverSetUp(){
          driver = new ChromeDriver();
   }



   @Test
   public void myTest(){

          TradeLane tradeLane = new TradeLane(driver);
          driver.get("*url*");
          tradeLane.businessTab().click();
          tradeLane.originCity().sendKeys("*city*");
          tradeLane.originPostalCode().sendKeys("*postalcode*");
          tradeLane.destinationCountry().sendKeys("*country*");
          tradeLane.destinationPostalCode().sendKeys("*postalcode2*");
          tradeLane.destinationCity().sendKeys("*city2*");
          tradeLane.describeYourShipment().sendKeys(Keys.RETURN);
   }

   @AfterTest
   public void closeDriver(){
          try {
                 Thread.sleep(15000);
          } catch (InterruptedException e) {
                 e.printStackTrace();
          }
          driver.close();
          driver.quit();
1 Answers

For the one who may be still interested in the answer I should say, The problem was in .xml file I have created on my own. Since I am using Intellij and Intellij does not create an xml file I had to make it myself and for whatever reason it caused some problems.

To tackle the issue I downloaded a plugin called "create testng xml", manually installed it on Intellij and by the use of that plugin I made the xml file for my project. https://plugins.jetbrains.com/plugin/9556-create-testng-xml/versions.

It is now working properly.

Related