Better TestNG Reports with ATU Reporter
TestNG has decent reporting capability in terms of its in-built reports. But for some purpose, they may not be as user friendly as you’d like it to be. ATU Reporter is an open source utility which we can use to generate good looking TestNG reports. In this post, we will explore how we can configure ATU Reporter with Selenium WebDriver.
Before we proceed, let’s clarify that ATU Reporter will be useful to you only if you are using TestNG. It does not depend on Selenium. That means it can be used during unit testing as well.
A bit about ATU Reporter:
It’s an open source utility for TestNG framework. Its TestNG Listeners(ATUReportsListener, ConfigurationListener and MethodListener) can be used to generate customized graphical reports such as Line Chart, Bar Chart and Pie Chart. It is built using JQuery, CSS, HTML and jqPlot charting library.
Now, let’s take a look at how we can configure it with Selenium WebDriver project. Follow below steps for it.
- Download latest version of ATU Reporter.
- Unzip the file which contains JAR files of ATU Reporter and ATU Test Recorder, Java-doc, Properties file and a Sample Project.
- Reference JAR files in your Selenium project.
- Open class file. We need to add ATUReportsListener.class, ConfigurationListener.class and MethodListener.class Listeners to it. Make sure you update your class file with necessary package imports.
12@Listeners({ ATUReportsListener.class, ConfigurationListener.class, MethodListener.class })public class ReportsTest { - Reference ATU Reporter properties file in your class file with below code.
123{System.setProperty("atu.reporter.config", "Path of properties file");} - Set the driver object to the ATU Reporter. You can modify indexPageDescription value with your choice of description.
123driver = new FirefoxDriver();ATUReports.setWebDriver(driver);ATUReports.indexPageDescription = "Test Project"; - The ATUReports class has four overloaded add methods for logging the step information. Add these four methods using below code.
1234567891011121314@Testpublic void testNewLogs() throws AWTException, IOException {ATUReports.add("INfo Step", LogAs.INFO, new CaptureScreen(ScreenshotOf.BROWSER_PAGE));ATUReports.add("Pass Step", LogAs.PASSED, new CaptureScreen(ScreenshotOf.DESKTOP));WebElement element = driver.findElement(By.xpath("/html/body/div/h1/a"));ATUReports.add("Warning Step", LogAs.WARNING,new CaptureScreen(element));ATUReports.add("Fail step", LogAs.FAILED, new CaptureScreen(ScreenshotOf.DESKTOP));} - After performing all above steps, your class file should be as below.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879package com.core.testscripts;import java.awt.AWTException;import java.io.IOException;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.interactions.Actions;import org.testng.Assert;import org.testng.annotations.AfterMethod;import org.testng.annotations.BeforeMethod;import org.testng.annotations.Listeners;import org.testng.annotations.Test;import atu.testng.reports.ATUReports;import atu.testng.reports.listeners.ATUReportsListener;import atu.testng.reports.listeners.ConfigurationListener;import atu.testng.reports.listeners.MethodListener;import atu.testng.reports.logging.LogAs;import atu.testng.selenium.reports.CaptureScreen;import atu.testng.selenium.reports.CaptureScreen.ScreenshotOf;@Listeners({ ATUReportsListener.class, ConfigurationListener.class,MethodListener.class })public class ReportsTest {{System.setProperty("atu.reporter.config", "C:\\atu.properties");}private WebDriver driver;private String baseUrl;@BeforeMethodpublic void setUp() throws Exception {driver = new FirefoxDriver();baseUrl = "https://www.google.co.in";driver.get(baseUrl + "/");// ATU ReportsATUReports.setWebDriver(driver);ATUReports.indexPageDescription = "Test Project";}@Testpublic void GoogleTooltip() throws Exception, SQLException {Actions ToolTip1 = new Actions(driver);WebElement googleLogo = driver.findElement(By.xpath("//div[@id='hplogo']"));ToolTip1.clickAndHold(googleLogo).perform();String ToolTipText = googleLogo.getAttribute("title");Assert.assertEquals(ToolTipText, "Google");System.out.println("Tooltip value is: " + ToolTipText);}// ATU Reports Method@Testpublic void testNewLogs() throws AWTException, IOException {ATUReports.add("INfo Step", LogAs.INFO, new CaptureScreen(ScreenshotOf.BROWSER_PAGE));ATUReports.add("Pass Step", LogAs.PASSED, new CaptureScreen(ScreenshotOf.DESKTOP));WebElement element = driver.findElement(By.xpath("/html/body/div/h1/a"));ATUReports.add("Warning Step", LogAs.WARNING,new CaptureScreen(element));ATUReports.add("Fail step", LogAs.FAILED, new CaptureScreen(ScreenshotOf.DESKTOP));}@AfterMethodpublic void tearDown() throws Exception {driver.quit();}} - Now, open your TestNG XML file and add necessary Listeners.
1234567891011121314<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"><suite name="Suite" parallel="false"><test name="Test"><classes><class name="com.core.testscripts.ReportsTest"/></classes></test><listeners><listener class-name="atu.testng.reports.listeners.ATUReportsListener"></listener><listener class-name="atu.testng.reports.listeners.ConfigurationListener"></listener><listener class-name="atu.testng.reports.listeners.MethodListener"></listener></listeners></suite> - That’s it. Now run your project using TestNG. You should be able to see customized graphical TestNG reports at location defined in ATU Reporter’s properties file.
Below is the output of above exercise. It shows TestNG reports in Bar Chart format.
As you can see, ATU Reporter is very useful in generating good looking TestNG reports. Give it a try and let us know if its useful in your case.
how to clear the runs in ATU Reports, y bcoz for every run it generates one report like Run1 like that, so i need to clear that Runs and i want the latest run report only.
So please tell me how to clear.
Thanks
Basha
To delete those reports, you can write a Java code at the start of the method.
Hi Maharshi how r u
I have 3 doughts like
1st one…..ATU Reports are working fine,but in before iam using testNg reports .And now iam adding ATU Reports.Its Working very well ,but the thing is like compare to previous my automation scripts are executing slowly,so the next steps will not catch fastly then iam getting NO SUCH ELEMENT EXCEPTION, So please tell me how do i executemy scripts fastly.
2nd one…. thing is iam not getting the line Charts reports,iam getting only Bar chart Reports,So tell me how do i get Line chart Reports.
3rd one….once i complete my execution igot ATU Reports then how do i EMAIl that reports to my seneour managers.
Please solve these 3 questions, you help me a lot.
Thanks
basha
Can anyone tell me how to email the emailable report.html file
to everyone in my team after the test is run.
Plz share the java code for deleting the Run folders
can you provide the java code to delete previous reports
Thanks
Saji
which method used for delete ATU report in java with DDF
I am able to zip the entire report folder , inorder to mail to the Group users.. However at this point we are end of the suite execution and index html is not created(Still run is pending)..can any one have any idea how we can stop the listeners in the middle of the execution to create index html at this point.. this will helps to zip the folder.
Please help me on same issue if u got the solution.
Priyanka
Hi Maharshi ,
Always Run1 is not genererated in the report.unable to change the report name & image, however changed the file path in atu.properties(atu.proj.header.logo) not working
thanks in advance
hai everyone…
please help me to get an idle solution to the unsolved problem of mine……
i have configured the ATU reporter jar files,and created the sample code and i have run the script using TestNG, test run was successfull but i am not able to get the ATU report.
please help me !!!!!!!!!!!!!!!
thank you…………..
you make one mistake – you should not include listeners into testng.xml, EITHER do it programatically via java, or via xml – not both! the instruction on atu reporter mainpage tells this… useless tutorial.
Any one help me out ….from this issue..
**********************************************
FAILED: testNewLogs
org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=43.0.2357.124)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.07 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.45.0’, revision: ’32a636c’, time: ‘2015-03-05 22:01:35’
System info: host: ‘SUMITJOSHITOWER’, ip: ‘10.0.17.102’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_71’
*** Element info: {Using=xpath, value=/html/body/div/h1/a}
Session ID: df0e6d2d1b5390d80f22fcc2c82a5625
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\SUMITJ~1.NEC\AppData\Local\Temp\scoped_dir6184_8092}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=43.0.2357.124, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:449)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at msip_ui.PerformancePage.testNewLogs(PerformancePage.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
***********************************************************************
Code
package msip_ui;
import java.awt.AWTException;
import java.io.File;
import java.io.IOException;
import java.sql.Driver;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import atu.testng.reports.ATUReports;
import atu.testng.reports.listeners.ATUReportsListener;
import atu.testng.reports.listeners.ConfigurationListener;
import atu.testng.reports.listeners.MethodListener;
import atu.testng.reports.logging.LogAs;
import atu.testng.selenium.reports.CaptureScreen;
import atu.testng.selenium.reports.CaptureScreen.ScreenshotOf;
@Listeners({ ATUReportsListener.class, ConfigurationListener.class,
MethodListener.class })
public class PerformancePage {
WebDriver driver;
private String downloadPath = “C:\\Users\\sumit.joshi.NECTECHNOLOGIES\\Downloads”;
private final static Logger logger = Logger
.getLogger(DesignEvaluation.class);
{
System.setProperty(“atu.reporter.config”,
“D:\\Automation\\ATU\\atu.properties”);
}
@BeforeTest
public void beforeTest() throws InterruptedException {
// ATU Reports
ATUReports.setWebDriver(driver);
ATUReports.indexPageDescription = “MSIP Functionality Validation using selenium webdriver.”;
System.setProperty(“webdriver.chrome.driver”,
“D:\\Automation\\chromedriver.exe”);
driver = new ChromeDriver();
driver.manage().window().maximize();
logger.info(“Going to browser Window Maximize”);
// Open URL(https://ntil:Redhat1@52.74.139.234/msip_ui/ui)
driver.get(“https://ntil:Redhat1@52.74.65.72/msip_ui/ui/”);
logger.info(“URL open : https://52.74.139.234/msip_ui/ui, With User Name:ntil and Password: Redhat1″);
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
Select SizingfactorName = new Select(driver.findElement(By
.cssSelector(“.sf_inputs”)));
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
SizingfactorName.selectByVisibleText(“tiny”);
Thread.sleep(10000);
// Button Click
driver.findElement(By.cssSelector(“#next”)).click();
logger.info(“Next button clicked”);
Thread.sleep(30000);
driver.findElement(By.id(“event_next”)).click();
Thread.sleep(30000);
logger.info(“event_next button clicked”);
Thread.sleep(45000);
}
@Test(priority = 23)
public void testNewLogs() throws AWTException, IOException,
InterruptedException {
ATUReports.add(“INfo Step”, LogAs.INFO, new CaptureScreen(
ScreenshotOf.BROWSER_PAGE));
ATUReports.add(“Pass Step”, LogAs.PASSED, new CaptureScreen(
ScreenshotOf.DESKTOP));
Thread.sleep(20000);
WebElement element = driver
.findElement(By.xpath(“/html/body/div/h1/a”));
logger.info(element);
logger.info(“element find”);
ATUReports.add(“Warning Step”, LogAs.WARNING,
new CaptureScreen(element));
logger.info(“Warning”);
ATUReports.add(“Fail step”, LogAs.FAILED, new CaptureScreen(
ScreenshotOf.DESKTOP));
logger.info(“Fail Step”);
}
@AfterClass
public void tearDown() {
driver.quit();
}
}
******************************************************************
Hi Guys,
I’m using indexPageDescription and setAuthorInfo but not seeing that text in the ATU Reports, and also how to generate the excel reports. Even i kept atu.reports.excel=true still not getting the excel reports….:( Please help me out 🙂
@BeforeMethod
public void setIndexPageDescription() {
ATUReports.indexPageDescription = “My Project Description This is TestNG Report“;
ATUReports.setAuthorInfo(“Appium”, “Test”, “Report”);
}
Below things also not coming in the ATU report
#change results directory
atu.reports.dir=C:\\Users\\Sateesh NV\\workspace4\\APPIUM\\Properties\\atu.properties
#change header text
atu.proj.header.text=TestNG + My Project TestCases
#add project/client logo, the image is copied to “HTML_Design_Files/IMG” directory
atu.proj.header.logo=C:\\Users\\Sateesh NV\\workspace4\\APPIUM\\Properties\\Appium.png
Please Guide to get resolve this problem
Hello,
I am new to ATU reporter.Can any one share working example for ATU reporter for understanding.
Thanks
Is there any property for disabling ATU reporting when ever required?
Hi,
Please help me on same issue if u got solution,
Thanks in advance
Hi,
I have been using ATU reporter quite some time now, I am successfully able to configure and able to generate reports while working with web applications. How ever i want to use ATU reporter framework to along with Appium framework to get the reports for mobile application automation.
I have implemented in the same way as we use to do with websites however I am unable to get screen-shots since ATUReporter.setWebDRiver() method.
Can anybody implemented ATU reporter tool for mobile platforms to generate reports, If any one please share the code.
Hi, I need clarification on report, Were one Test case with different test data report. Currently it showing ConsolidatedPage iteration of test case.i need iteration of test data after clicking on Test case. Like Test Case(Login) –> data set (1.Negative.2.Skip.3.Positive data).
java.lang.IllegalStateException: [ATU Custom Reporter Exception] Unable To Create Required Files for Custom Reports
at atu.testng.reports.listeners.ATUReportsListener.initChecking(Unknown Source)
at atu.testng.reports.listeners.ATUReportsListener.onExecutionStart(Unknown Source)
at org.testng.TestRunner.initListeners(TestRunner.java:361)
at org.testng.TestRunner.init(TestRunner.java:245)
at org.testng.TestRunner.init(TestRunner.java:212)
at org.testng.TestRunner.(TestRunner.java:166)
at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:143)
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:272)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:587)
at org.testng.SuiteRunner.init(SuiteRunner.java:161)
at org.testng.SuiteRunner.(SuiteRunner.java:114)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1290)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1277)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1131)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)
Caused by: [ATU Custom Reporter Exception] Unable To Create Required Files for Custom Reports
at atu.testng.reports.utils.SettingsFile.create(Unknown Source)
at atu.testng.reports.utils.SettingsFile.initSettingsFile(Unknown Source)
at atu.testng.reports.utils.Directory.verifyRequiredFiles(Unknown Source)
… 18 more
I am using this below code but screen shot not generated in report . please help me
package Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import atu.testng.reports.ATUReports;
//import atu.testng.reports.ATUReports;
import atu.testng.reports.listeners.ATUReportsListener;
import atu.testng.reports.listeners.ConfigurationListener;
import atu.testng.reports.listeners.MethodListener;
import atu.testng.reports.logging.LogAs;
import atu.testng.reports.utils.Utils;
import atu.testng.selenium.reports.CaptureScreen;
import atu.testng.selenium.reports.CaptureScreen.ScreenshotOf;
@Listeners({ ATUReportsListener.class, ConfigurationListener.class,
MethodListener.class })
public class atu
{
WebDriver driver;
private void setAuthorInfoForReports()
{
ATUReports.setAuthorInfo(“Automation Tester”, Utils.getCurrentTime(),
“1.0”);
}
//@SuppressWarnings(“deprecation”)
@Test
public void f()
{
System.setProperty(“atu.reporter.config”, “C:\\Users\\gobi\\workspace\\Test\\ATUReporter”);
ATUReports.setWebDriver(driver);
setAuthorInfoForReports();
// System.setProperty(“atu.reporter.config”, “C:\\Users\\gobi\\workspace\\Test\\ATUReporter”);
System.setProperty(“webdriver.chrome.driver”, “./lib/chromedriver.exe”);
driver=new ChromeDriver();
//driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“http://www.learn-automation.com”);
setAuthorInfoForReports();
// ATUReports.add(“test url done”, true);
ATUReports.add(“INfo Step”, LogAs.PASSED, new CaptureScreen(ScreenshotOf.DESKTOP));
}
}
HI i am triying to run the scripts in parallel in Firefox,chrome,ie browsers ,but in reports i am only getting one browser reports…what about other vrowsers reports?????…can we have solution for this???
Exception in thread “main” java.lang.IllegalStateException: java.lang.NullPointe rException at atu.testng.reports.listeners.ATUReportsListener.onFinish(Unknown Sour ce) at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:204) at org.testng.SuiteRunner.run(SuiteRunner.java:264) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215) at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at org.testng.TestNG.run(TestNG.java:1048) at org.testng.TestNG.privateMain(TestNG.java:1355) at org.testng.TestNG.main(TestNG.java:1324) Caused by: java.lang.NullPointerException at atu.testng.reports.writers.CurrentRunPageWriter.getTestCaseHTMLPath(U nknown Source) at atu.testng.reports.writers.CurrentRunPageWriter.writeFailedData(Unkno wn Source) at atu.testng.reports.writers.CurrentRunPageWriter.content(Unknown Sourc e) at atu.testng.reports.listeners.ATUReportsListener.generateCurrentRunPag e(Unknown Source) … 10 more
Any idea?
Hi,
When i run the scripts parallel then atu reports are showing wrong. every time it takes the screen short on active screen(browser which is visible to user) on desktop.
So test description is fine but screen shot is showing wrong and it is not related one
Hi,
Can the test name different than the test method name ?
for example ‘GoogleTooltip’ is the @Test method name in the reports this what will be printed.
Instead i need my own test name other like ‘Goole Tool Tip on the right cornet of the webpage’
Hi, I love this reporter.
I am new to testing and programming but found it easy enough to use.
Question: I wonder is it possible to include the expected and actual results into the report, or else to just edit the table header in the run page so that it only shows Step Description, Time, Line Number, Status and Screeshot? (So to remove the columns for the Input Value, Actual Value and Expected Value from the rendering of the report run page?)
Thanks.