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?
- reportNG – HTML report plugin for TestNG
- Guice – Dependency injection framework
- Velocity dep- Java-based template engine
Click on your testNG test case file which you want to run and find “TestNG” and click on “Convert to TestNG”
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:
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.
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.
You can achieve much more and add almost anything to the report file by downloading the git source from
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.