A perfect test automation tool is what you need for the successful execution of the testing requirements in the agile process. And there are multiple factors which play a critical role in the formation of a robust automation framework. One such factor is reporting which not only make you aware of the status of the success or failure but helps you in finding out the potential bugs. A good Report serves as a health card of the ongoing project which you can share with the stakeholders. So, you should mindfully choose how you are going to generate reports in Selenium Webdriver project. That’s where this blog would lead you to make a decision. You’ll see two cutting edge techniques that can help you generate reports which are user-friendly, untaught and informative.

Before we proceed with the topic, it is essential that you clearly understand what is the purpose of reporting? You need it because:
1. Test Report gives stakeholders a definite idea of the actual state of the product so that they can decide to ship it to the customer or allow the team to focus on the shortcomings.
2. Reports help you to identify the status of the test case (Pass/Fail/Skip).
3. Using reports we calculate time taken by each test case that helps to calculate ROI (Return on Investment).

 

What are the essential qualities of a good test report?

  • Briefness –
    • A report should be short and concise.
    • It should clearly state the proportion of total no. of success or failure.
  • Traceability –
    • It must provide the ability to review the following.
      • Historical data for test cases and failures.
      • Age of a particular failure & root cause of failure
  • Sharable –
    • It should support a format which you can share through email or integrate with CI tools like Jenkins/Bamboo.
  • Test coverage –
    • It should highlight the test coverage for the following.
      • Test coverage of the module under test.
      • Test coverage of the application under test.

Now you would have gained a fair idea of the fact that how a good test report can maximize the returns on investment. Let’s move our focus to two techniques that you may use to generate reports in Selenium Webdriver.

Two Techniques to Generate Reports In Selenium Webdriver.

Selenium Webdriver doesn’t have a built-in reporting feature but there are plugins like the TestNG and JUnit which can add this functionality.

1- Generate Reports Using TestNG.

TestNG library brings a very convenient reporting feature. Once you execute the tests, TestNG generates a test output folder at the root of the project. It combines two kinds of reports.

Two web reports in TestNG

Detailed Report

You can find this report in the <index.html> file. It combines the detailed information like the errors, test groups, execution time, step-by-step logs and TestNG XML file.

Generate Reports (index.html) in TestNG.

Summary Report

It is the trimmed version and informs about the test pass/fail/skip count. You can see it from the <emailable-report.html> file. It’s an email friendly report which you can embed and share with the stakeholders.

Generate Reports (emailable-report.html) in TestNG.

1.1- Steps To Generate Reports Using TestNG.

Step-1) Select The TestNG Reporting Interface.

TestNG reporting is quite handy but still, sometimes we need some less data in reports or want to display reports in some other format like pdf, excel, etc. or want to change report’s layout.

There can be two ways we can customize TestNG report

  • Using ITestListener Interface
  • Using IReporter Interface which is least popular.

In this blog post, we’ll cover the application of the ITestListener Interface. You’ll have to create a TestNG project in Eclipse.

Step-2) Generate Reports Using The <ITestListener> Interface.

Step-3) Verify The Report Generation Process.

Once you run the above code, it’ll launch the specified URL in Browser and produce a spontaneous TestNG report. The final test report would look like the one shown in the below screenshot.

Sample TestNG Report

 

2- Generate Reports Using Extent Library.

Another technique for generating some awesome reports is by using the Extent Report library. It comes with a rich set of features.

  • Ability to generate dynamic HTML logs.
  • Represents test case status with the help of PIE Charts.
  • Generates step-by-step test case summary.
  • Ability to filter reports based on test status.
  • It maintains execution history.
  • It captures details like OS, Memory, Java version and so on.
  • You can attach error screenshots within the report.
  • Open source reporting library – easily Integrated with all test frameworks.

 

Step-1) Download the Extent library from the below URL.
http://extentreports.com/community/(Download Version Java  –  2.41.2)

Once you have the reporting library, then follow the below steps to use them in a Selenium Webdriver project.

Step-2) Add the Jar files shown in the above picture as external libraries to your project.

Make sure to add the Jars that are under the <lib> folder else the exception may occur at run-time.

Step-3)   Initialize Extent Reports and Extent Test

 

Step-4) Create a html report specifying absolute path & Start Test

Step-5) Write Test case & specify the Pass fail conditions in try catch block for each step

Step-6) After the Test case – Stop test & flush report

Step -7) Optional: Open the html in browser right after your test case

Note : this is same path given in Step-4

Once you run the above code, it’ll launch the specified URL in Browser and produce a spontaneous Extent test report. The final test report would look like the one shown in the below screenshot.


Extent Report Sample

 

Happy testing!!

Leave a Reply