Sneha,
Since you mention factories, you can do something like below :
Define an interface which will expose the data that is passed to your test class instance.
Have your test class implement this interface so that it can be invoked from outside.
In your onSkipped() implementation of your listener you can now invoke this interface method to get this data.
Here's a sample implementation which shows what I am talking about.
public interface RowInfo {
int getRowId();
}
@Listeners (InfoOnSkippedTests.TestDetailsListener.class)
public class InfoOnSkippedTests implements RowInfo {
private int rowId;
@Factory (dataProvider = "dp")
public InfoOnSkippedTests(int rowId) {
this.rowId = rowId;
}
@DataProvider (name = "dp")
public static Object[][] getData() {
return new Object[][] {
{1},
{2}
};
}
@Test
public void testMethod1() {
System.err.println("Hello from testMethod1()");
throw new RuntimeException("Failing testMethod1()");
}
@Test (dependsOnMethods = "testMethod1")
public void testMethod2() {
System.err.println("This is never going to be executed");
}
@Override
public int getRowId() {
return rowId;
}
public static class TestDetailsListener extends TestListenerAdapter {
@Override
public void onTestSkipped(ITestResult result) {
Object instance = result.getMethod().getInstance();
if (! (instance instanceof RowInfo)) {
return;
}
int rowId = ((RowInfo) instance).getRowId();
System.err.println("Test Method " + result.getMethod().getConstructorOrMethod().getName()
+ "() skipped for rowId: " + rowId);
}
}
}