You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all thanks for creating a sample listener which is very useful. But i'm stuck in a small issue.
I want to create a node at class level. I'm using the listener as follows
@Override
public void onStart(ITestContext iTestContext) {
ISuite iSuite = iTestContext.getSuite();
ExtentTest suite = (ExtentTest) iSuite.getAttribute(SUITE_ATTR);
ExtentTest testContext = suite.createNode(iTestContext.getName());
iTestContext.setAttribute("testContext", testContext);
System.out.println("ClassName is : " + returnClassName(iTestContext));
}
@Override
public void beforeInvocation(IInvokedMethod iInvokedMethod,
ITestResult iTestResult) {
ITestNGMethod method = iInvokedMethod.getTestMethod();
System.out.println("Class Name Inside before Invocation Method: "
+ returnClassName(method));
if (iInvokedMethod.isTestMethod()) {
ITestContext iTestContext = iTestResult.getTestContext();
ExtentTest child = (ExtentTest) iTestContext
.getAttribute("testContext");
cNode = child.createNode(returnMethodName(iInvokedMethod
.getTestMethod()));
iTestResult.setAttribute("test", cNode);
String textMsg = "About to begin executing following method : "
+ "<b>" + returnMethodName(iInvokedMethod.getTestMethod())
+ "</b>";
Reporter.log(textMsg, true);
}
}
@Override
public void afterInvocation(IInvokedMethod iInvokedMethod,
ITestResult iTestResult) {
if (iInvokedMethod.isTestMethod()) {
ExtentTest test = (ExtentTest) iTestResult.getAttribute("test");
List<String> logs = Reporter.getOutput(iTestResult);
for (String log : logs) {
test.info(log);
}
int status = iTestResult.getStatus();
if (ITestResult.SUCCESS == status) {
test.pass("Passed");
} else if (ITestResult.FAILURE == status) {
test.fail(iTestResult.getThrowable());
} else if (ITestResult.SKIP == status) {
test.skip(iTestResult.getThrowable());
} else {
Reporter.log("Please check the script..!!");
}
for (String group : iInvokedMethod.getTestMethod().getGroups()) {
test.assignCategory(group);
}
String textMsg = "Test executing of : " + "<b>"
+ returnMethodName(iInvokedMethod.getTestMethod()) + "</b>"
+ " is completed ";
Reporter.log(textMsg, true);
}
}
@Override
public void onFinish(ITestContext iTestContext) {
ExtentTest testContext = (ExtentTest) iTestContext
.getAttribute("testContext");
if (iTestContext.getFailedTests().size() > 0) {
testContext.fail("Failed");
} else if (iTestContext.getSkippedTests().size() > 0) {
testContext.skip("Skipped");
} else {
testContext.pass("Passed");
}
}
This report is giving all the methods inside tag in xml.
Xml that am using is:
I want to create a node when a tag is encountered.
Any help would be really helpful. Looking forward for your reply.
Thanks & Regards,
Sandeep.
The text was updated successfully, but these errors were encountered:
Hi Vimal,
First of all thanks for creating a sample listener which is very useful. But i'm stuck in a small issue.
I want to create a node at class level. I'm using the listener as follows
This report is giving all the methods inside tag in xml.
Xml that am using is:
I want to create a node when a tag is encountered.
Any help would be really helpful. Looking forward for your reply.
Thanks & Regards,
Sandeep.
The text was updated successfully, but these errors were encountered: