Generate PDF Report of Selenium Test Execution

When using Selenium WebDriver for testing, testers often need to generate test execution report. Sure, TestNG does a great job at producing a report in HTML and XML format. But what if there is a need to generate a PDF report? We can very much do this with help of iText PDF library and TestNG listeners. We will see how to do it in this post.

A small background:
To generate PDF report, we have used iText PDF library here. It’s an open source library which can be used to manage PDF files. We have already seen how to use iText to read PDF content using Selenium WebDriver code. In this tutorial, we’ll use this library with custom TestNG listener to generate a PDF report at the end of test execution. This custom TestNG listener is created by Thierry Janaudy in Java using ITestListener.

OK, enough with the talks. Let’s get into action.

  • Download IText JAR file and custom listener.
  • Reference the downloaded JAR file in your project.
  • Copy the custom listener( in your project’s source directory. Make required modification in that file to get rid of any errors.
  • Add JyperionListener.class as listener in class file for which you want the report generated. You can add it as a listener by making its reference at your class declaration. Similar to below code.
  • Run your test using TestNG.
  • At the end of your test execution, you should see PDF file generated in your project’s root directory.

Below is a screenshot of PDF report generated.PDF Report using Selenium WebDriver

The report contains some useful information like stack trace and test cases duration.

So to summarize, iText API is pretty handy in case you want to deal with PDF files in your Selenium WebDriver project. Give it a try in your project and let us know how it goes for you.

  1. Kapil soni
    • uttesh
      • Gs
  2. Jitendra
  3. Darshit
    • Swati Gupta
  4. ikky

Leave a Reply

Your email address will not be published.