ReportNG

reportng

Reporting plays a very important part of test automation and ReportNG is a very helpful TestNG plugin which is powerful and easily customizable. Actually, the extent of customization is huge.

This is going to be a quick intro tutorial to ReportNG, my goal is to quickly show how to set it up and add basic functionality.

How to set up?

Download reportNG library

Download Guice

Download Velocity dep

  • reportNG – HTML report plugin for TestNG
  • Guice – Dependency injection framework
  • Velocity dep- Java-based template engine

Next step.

Click on your testNG test case file which you want to run and find “TestNG” and click on “Convert to TestNG

reportng

Now you’ll see the generated XML windows, you’ll have to add these four listeners to the XML file.

So the generator screen will look like this:

Capturelistners

Now when you have generated an XML file, click on XML file and choose TestNG -> Run as TestNG

So this will create a new directory in your project:

test-output -> HTML

Here you’ll find index.html which will have the basic reportNG template.


Improving ReportNG

You can add screenshot and text to the file by using Reporter.log(“””) this is TestNG specific function which adds a line to the report file. Since we are using ReportNG which is HTML5 compatible, we can easily add short HTML “scripts” and it will execute.

Add an Expand/Collapse Screenshot:

Reporter.log(<details> <summary>Click to expand</summary><img alt="" /></details>");

Just change pathToScreenshot to your full path which includes the file name. the expand collapse will mainly work only on chrome.


Advanced stuff

You can achieve much more and add almost anything to the report file by downloading the git source from
ReportNG Git

Most of the stuff is located in ReportNG-base.java, however, you can find useful stuff through all of the projects. You can inject jQuery library and use it to add the script to the template so it’s possible to make these expand/collapse images for all of the browsers, also you can edit almost everything there, adding your logo, descriptions, CSS improvements and jQuerry components.

reportNGexample

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s