-
Notifications
You must be signed in to change notification settings - Fork 318
CreateTest when called with same TestName does not create another test with same name. #1108
Comments
Can you share the iTestListener code? |
Yes Sure .. |
public class CustomListener extends BaseTestClass implements ITestListener {
/just to ignore a specific test from adding to the report/
@OverRide
|
@yogitthakral can you please format your code so it's readable? |
Please try with this: public class ExtentITestListener
implements ITestListener {
private static final ExtentReports EXTENT = Extent.getInstance();
private static ThreadLocal<ExtentTest> methodTest = new ThreadLocal<ExtentTest>();
private static ThreadLocal<ExtentTest> dataProviderTest = new ThreadLocal<>();
@Override
public synchronized void onStart(ITestContext context) { }
@Override
public synchronized void onFinish(ITestContext context) {
EXTENT.flush();
}
@Override
public synchronized void onTestStart(ITestResult result) {
String methodName = result.getMethod().getMethodName();
if (result.getParameters().length>0) {
if (methodTest.get() != null && methodTest.get().getModel().getName().equals(methodName)) { }
else {
createTest(result);
}
String paramName = Arrays.asList(result.getParameters()).toString();
ExtentTest paramTest = methodTest.get().createNode(paramName);
dataProviderTest.set(paramTest);
} else {
createTest(result);
}
}
private void createTest(ITestResult result) {
String methodName = result.getMethod().getMethodName();
ExtentTest test = EXTENT.createTest(methodName);
methodTest.set(test);
String[] groups = result.getMethod().getGroups();
if (groups.length > 0) {
Arrays.asList(groups)
.forEach(x -> methodTest.get().assignCategory(x));
}
}
@Override
public synchronized void onTestSuccess(ITestResult result) {
getTest(result).pass("Test passed");
}
private ExtentTest getTest(ITestResult result) {
ExtentTest t = result.getParameters() != null && result.getParameters().length>0
? dataProviderTest.get()
: methodTest.get();
return t;
}
@Override
public synchronized void onTestFailure(ITestResult result) {
getTest(result).fail(result.getThrowable());
}
@Override
public synchronized void onTestSkipped(ITestResult result) {
getTest(result).skip(result.getThrowable());
}
@Override
public synchronized void onTestFailedButWithinSuccessPercentage(ITestResult result) { }
} |
Thank you so much for helping me out here Pardon me for code formatting ... I already tried a similar approach by placing a suffix to retried test case as "retry{counterOfRetry} What I mean to say , is After Flushing and before creating another test case , if thread is having any logs , its writing to the previous test case . |
I have implemented extent report 3.1.5 via ITestListener interface and using retryAnalyzer in my testsuite.
I hope ,I am able to explain the situation , please help me to get over it , Am I missing something here or doing it the wrong way ?
Thanks,
Yogit Thakral
The text was updated successfully, but these errors were encountered: