Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a node at class level #3

Open
sandeepmummoji opened this issue Jan 11, 2017 · 0 comments
Open

How to create a node at class level #3

sandeepmummoji opened this issue Jan 11, 2017 · 0 comments

Comments

@sandeepmummoji
Copy link

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

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant