Wednesday, October 2, 2013

Generate ReportNG report using Maven

Earlier I had covered in my blog about generating TestNg-xslt report for your TestNG test execution using Maven. Following is the link to it:


In this blog I will write about how to generate a ReportNG report for your TestNG test execution using maven. Following is a pom.xml file that can be used to execute your tests in a maven project and also generate a ReportNG report after execution.



Run the following command to run your test cases and generate the ReportNG report.

mvn clean test

Or just

mvn test

Once run by default the execution report can be found under the folder named "html" under the surefire report directory inside "target" folder of your project folder.

24 comments :

Jeevan said...

Thanks Varun for the post, but I am not able to generate XSLT reports . Below pom only gives reportng reports: Please let me know whats wrong in it:
I have tried :
mvn clean test
mvn test
mvn clean and then mvn test but it didnt give xslt report in the HTML folder.

4.0.0

com.delete_xslt
creams
0.0.1-SNAPSHOT
jar

creams
http://maven.apache.org



src/test/resource

**/*.java










org.apache.maven.plugins
maven-surefire-plugin
2.14.1





listener

org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter



target/



maven-compiler-plugin
2.3.2

1.7
1.7













com.google.inject
guice
3.0
test


org.uncommons
reportng
1.1.4


org.seleniumhq.selenium
selenium-java
2.34.0


org.seleniumhq.selenium
selenium-support
2.34.0



org.seleniumhq.selenium
selenium-api
2.34.0


org.testng
testng
6.8.5




How you are able to write nice posts ob this page but our reply looks very bad?

Varun Menon said...

You can use gist to provide link your code snippets.

Varun Menon said...

The combined pom.xml file is available at following location:

https://gist.github.com/menonvarun/6865213

Jeevan said...

I dont know what it is and how to use it with this page... :)

Varun Menon said...

Gist is a simple way to share your code snippets with others. You add a code and give it a description and name. Gist will give you a url which you share with others ans they can refer to it. In this case your pom.xml.

Gist url is:
https://gist.github.com/

Anyways I had written a combined pom xml for both reportng and testng xslt which i had shared in my earlier comment in this post.

PIYUSH said...

great work Varun. It helped me a lot.

Anonymous said...

Hi Varun can you check for this please "ArtifactTransferException: Failure to transfer velocity:velocity-dep:jar:1.4 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact velocity:velocity-dep:jar:1.4 from/to central (http://repo.maven.apache.org/maven2): No response received after 60000"

Unknown said...

Hi Varun,

I have a requirement where i need to generate testng xslt report from junit code using maven. Can you please let me know the plugins to use and the code to execute the same?

Paul Levesque said...

@Mannat, there is only one way to use "ant run" plugin in pom.xml and call your build.xml. Else there is no way to do it.

Unknown said...

Hi Paul,

Thanks for your reply. I am completely new to maven and ant. Could you help me if i provide my pom.xml? As my application is using maven only as the build tool

Paul Levesque said...

I can but I dont want to :D
Because its really simple stuff that you can achieve just by spending some time. If not then search on google you will find it, or put it on forums like stackoverflow, google etc.

Unknown said...

Thanks!

Mukesh Otwani said...
This comment has been removed by a blog administrator.
Mukesh Otwani said...
This comment has been removed by a blog administrator.
uttesh said...

Use pdfngreport plugin to generate the pdf report, which support both maven/ant

https://github.com/uttesh/pdfngreport

Mr. Router said...

Hi Varun,

Thanks for the post but i am getting this error still :

[ERROR] org.apache.maven.surefire.testset.TestSetFailedException: Cannot find li
stener class
[ERROR] org.uncommons.reportng.JUnitXMLReporter; nested exception is java.lang.C
lassNotFoundException:

Can you help quickly ?

Thanks,
Jatin

Varun Menon said...

Most probably your reportng was not included in the class path of the class/ package name for the JUnitXmlReporter in ReportNg has been changed.

Unknown said...

Hi Varun,
Thanks a lotttt for your great post. Really awesome.
I have a requirement that the generated reports should get stored on a "Network drive". Currently we are running the scripts for every one hour thru pom.xml batch file. So the reports should get generate accordingly and should be stored on Network drive. We are not using Ant's build.xml. So how can we achieve this thru pom.xml.. How can I mention the path in that file. Could you please help me on this..
Thank you.

Varun Menon said...

Try setting the property "maven.testng.output.dir" as a system property in maven with your network directory path.

Unknown said...

Thank you Varun.. I will try and let u know..

Unknown said...

Now I can able to generate the reports and can able to store only on local machine. But when I try to store the same reports on to Network drive there it is displaying exception on console as I haven't provided username and password. How can I provide those details through java code.
Below is CustomReporter class..

public class CustomReporter implements IReporter
{
File fd = new File("");
String date;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss");
String folderNameWithTimeStamp = df.format(new Date());
String currentDir = System.getProperty("user.dir") + "//Reports//";
String finalPath = currentDir + folderNameWithTimeStamp;
@SuppressWarnings("deprecation")
@Override
public void generateReport(List xmlSuites, List suites, String outputDirectory)
{
TestNG.getDefault().setOutputDirectory(finalPath);
TestNG.getDefault().setXmlSuites(xmlSuites);
XmlSuite suite = new XmlSuite();
List suites1 = new ArrayList();
suites1.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites1);

}
}

Unknown said...

Hi Varun,

You made an awesome blog. It's really very useful. Thanks for it.

Could you please explain a simple example on, how to handle Client side application and Server side application at the same time using Selenium WebDriver?

Many thanks in Advance.

Varun Menon said...

Selenium being a functional test tool do both kind of testing together since it works on the browsers you automatically executing the client side code as well as server side code which is utilized by the client. The only issue will be to identify exactly where the issue is client side or server side.

It is always advisable to have separate unit tests for both client and server side and validate the individual functionality but in case they dont get caught in such scenario, you may need to look for rest option to validate the server side testing. I wont suggest to use Selenium to do a in-depth test of both client or server side.

Unknown said...

Hi, how do we consume this reportng and prepare a aggregated/consolidated unit test report at the root directory?

Post a Comment