Home > Net >  Parallel execution using TestNg Selenium in a POM framework overwriting the data object class
Parallel execution using TestNg Selenium in a POM framework overwriting the data object class

Time:02-10

I am trying to run two test classes in parallel both are using data providers pointing to different excel sheets. Sequentially it runs fine, but while running it in parallel it seems like the test object class which is holding all the test data is getting overwritten. Below is the data provider
Class 1

  @DataProvider(name = "tradeData"  ) 
   public Object[][] createMessage() {
   return ExcelUtils
    .getDataFromExcelSheet("TestSheet1", LOADTESTDATAPROVIDER);
    }}

Class 2

 @DataProvider(name = "tradeData")
   public Object[][] createMessage() {
   return ExcelUtils
    .getDataFromExcelSheet("TestSheet2", LOADTESTDATAPROVIDER);
    }

The data is being returned correctly from the excel but it seems like it is getting overwritten when placed into the object class. The data object class is being initialized from both test classes something like this

 @Test(dataProvider = "tradeData")
  public void connectAndPushMessage(String sellerName,
   String buyerName,
   String SIN){

testMessage tMessage = new testMessage();
tMessage.setSellerName(sellerName);
tMessage.setBuyerName(buyerName);
tMessage.setSIN(SIN);
    }

Below is the testng.xml that I have used.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
  <suite name="Parallel Testing" parallel="classes" thread-count="2">
    <test name="Test run 1">
    <classes>
        <class name="test.xxx.performance.InjectTrades_TestRun1"/>
        <class name="test.xxx.performance.InjectTrades_TestRun2"/>
    </classes>
  </test>
 </suite>



<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
  <suite name="Parallel Testing" parallel="tests" thread-count="2">
     <test name="Test run 1">
       <classes>
         <class name="test.xxx.performance.InjectTrades_TestRun1"/>
        </classes>
     </test>

<test name="test run 2">
    <classes>
  <class name="test.xxx.performance.InjectTrades_TestRun2"/>
    </classes>
</test>

I am getting the same result from both xmls so rather six distinct messages being created/pushed into the system(based on two excel sheets) the code is pushing three distinct messages repeated twice. I was/am under the impression that testNg should have take care of this as both classes/tests are running as separate threads.

CodePudding user response:

  •  Tags:  
  • Related