3

actually data provider have date and brand name so my first @test can only select date and brand name then in second @test it will fetch data against the same date and brand name and on second iteration first @test take second date and second brand name from @dataprovider and then second @test will do their own work and so on please help me thanks in advance. example is given below :

`@DataProvider
  public static Object[][] dp() {
    return new Object[][] {
      new Object[] { "23", "Online" },
      new Object[] { "24", "Online" },
    };
  }
@Test(dataProvider = "dp")
  public void DateAndBrand(String date,String game) throws InterruptedException{
System.out.println(date"  "+game)
}
@Test
  public void CheckDifference(){
System.out.println("in second Test");
} 

I want output something like :

23  Online 
in second Test
24  Online
in second Test

My testng.xml file is given below :

<suite name="Automation" parallel="false">
<test name="Data Difference">
<classes>
 <class name="monitoring.DataCompareAuto">
  <methods>
        <include name="DateAndBrand"/>
        <include name="CheckDifference" />
    </methods>
  </class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Sumit kumar
  • 33
  • 1
  • 5

1 Answers1

0

Whenever we use the dataProvider attribute with @Test annotation that method is called the number of times the number of object in array returned by @DataProvider.

To achieve the output that you are referring, you can use the ITestListener interface or TestListenerAdapter class.

Using these listeners you can intercept each and every test method on start, success, faliure etc. You can perform any operation there.

import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class TestInterceptor implements ITestListener {
    @Override
    public void onFinish(ITestContext arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onStart(ITestContext arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onTestFailure(ITestResult arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onTestSkipped(ITestResult arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onTestStart(ITestResult arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onTestSuccess(ITestResult arg0) {
        System.out.println(" Can perform CheckDifference operation here.");

    }

}

So your output in this case will be

23  Online
 Can perform CheckDifference operation here.
24  Online
 Can perform CheckDifference operation here.
in second Test
 Can perform CheckDifference operation here.

Do remeber to add the listener in your testng.xml file

Lord Nick
  • 582
  • 8
  • 29
  • thanks it works fine but in my code when i write @Override public void onTestSuccess(ITestResult arg0) { driver.findElements(By.tagName("tr")); } it is giving an exception as noelement found. – Sumit kumar Nov 27 '17 at 04:36
  • This is because of java compiler. Your project must have java compiler version older than 1.6 . Change it to a recent compiler version from Project > Build Path. Let me know if it helps. – Lord Nick Nov 27 '17 at 04:50
  • No java compiler version is 1.8 . its not works. i added the tag just above to tag . is it correct way to put right? and please help if other way – Sumit kumar Nov 27 '17 at 05:36
  • Please check the following link https://stackoverflow.com/questions/15402615/override-is-not-allowed-when-implementing-interface-method – Lord Nick Nov 27 '17 at 09:39