Software Testing Class

PDF, Emails and Screenshot of Test Reports in Selenium

In this chapter, we are going to discuss the generation of the test reports in the presentable format to higher management and development team to report the defects and the testing progress. The presentable formats of test reports are PDF, email, and screenshots.

Test automation is not only the procedure to automate the test cases but also, it is the responsibility of the testers to execute the automated test suite, find the defects and report these defects or bugs to the development team to fix and the higher management to keep the track of the application under test. Such reports must be in a very presentable format such has it should be very comprehensive to understand and complete in its entirety.

TestNG Framework Test report

TestNG framework library provides a test report in HTML format every time the execution of the test suite is completed. It creates a test-output folder that is present at the root of the test project. This folder contains two types of test reports which are as follows:

TestNG_Index
Click Image To Enlarge
Click Image To Enlarge

 

Customisation of TestNG Report

TestNG default reports are very detailed and handy. But still sometimes, we need to customize the report as per the team requirements such as remove or add one or more fields from the report, change the report layout, display the report in different format such as PDF, html, excel, etc. for all of such requirement TestNG framework has two interfaces that help in report customization as follows:

  1. ITestListener Interface.
  2. IReporter Interface.

ITestListener Interface

This interface is used to customize real-time test report i.e. when we execute a handful of test cases using TestNG framework and we desire a report for an individual test case. In this scenario, for each test case, we have to implement ITestListener interface which will override onTestFailure, onTestSuccess, onTestStart, onTestSkipped, onFinish methods to convey the correct status of the currently executing test case into the report.

Following are the steps to use ITestListener interface to customize TestNG report

Click Image To Enlarge

Class TestNGReporting that implements ITestListener interface

Click Image To Enlarge

Class TestReport that listens to class TestNGReporting

Click Image To Enlarge

Output

When we run the TestReport as TestNG test, we will obtain the following test reports.

Click Image To Enlarge
Click Image To Enlarge
Click Image To Enlarge
Click Image To Enlarge

IReporter Interface

This interface is implemented to customize the final test report that is generated by TestNG framework. It has only one method to override i.e. generateReport. This method possesses all the required information to complete the test execution in the List<ISuite> with which report can be generated.

Following are the steps to use IReporter interface to customize TestNG report

Class TestReporterInterface that implements IReporter interface

Click Image To Enlarge

Class TestReporterReport that listens to class TestReporterInterface.

Click Image To Enlarge

Output

When we run the TestReporterReportas TestNG test, we will obtain the following test reports.

Click Image To Enlarge
Click Image To Enlarge
Click Image To Enlarge
Click Image To Enlarge

Test Screenshot

While running the automation test suites using Selenium WebDriver, if defects are found then they are momentary and does not explain much of the details. In such case, it is desirable to take the screenshot which will capture all of the details of the defect. This helps the developer in bug analysis. Selenium WebDriver can take screenshots automatically with the help of class TakesScreenshot that is present in Selenium WebDriver API. In a similar way, we can generate PDF files as well.

Following is the demonstration of a test script in Java to take test screenshot of a website using WebDriver API.

Click Image To Enlarge

Explanation of the test script

 

 Output

When we will run the above test script, it will capture a full screenshot of the website home page located at URL https://www.softwaretestingclass.com/and will copy that screenshot PNG file to local drive (Path as“ c://selenium_demo//screenshot.png”). Shown below is the captured screenshot.

Click Image To Enlarge

Conclusion

In this chapter, we are have learned to generate various kind of the test reports in the presentable format. Such as HTML, customized reports, PDF, email, and screenshots.

 


Subscribe Us


If you are not a regular reader of this website then highly recommends you Sign up for our free email newsletter!! Sign up just providing your email address below:

Enter your email address:

Check email in your inbox for confirmation to get latest updates Software Testing for free.

Happy Testing!!!

Exit mobile version