Scroll to top

10e. Advanced WebDriver – Generating a PDF report

Hiya Champs! We have covered a lot of ground on reports so far, and you have reached the climax article. Generating an HTML report may not be that helpful if you want to attach it to an email and send it to your stakeholders. Because the ANT generated JUnit report has an index.html file which in turn embeds a few other HTML files such as overview-frame.html, all classes-frame.html, and overview-summary.html files.

What do we do in this situation? How do we attach this to an email? Can we not get it as a single file instead of a set of HTML files? – A single answer to all these questions is, to generate a PDF file instead.

Let us look at the procedure for generating a PDF report without disturbing the customizations we made thus far,

Step 1:

We require a JUnit PDF Report essentials distribution. It contains all the required dependencies as well. Download the latest version of the ‘essentials’ zip file from the link, ‘’

PDF Essentials Download

Unzip the file contents to a local folder and make a note of the path. Also, make sure the distribution contains ‘build-junitpdfreport.xml’ file and ‘lib’ folder along with certain other files and folders.

Step 2:

Time to flip to our ‘Build.xml’ file in eclipse IDE. There are few lines to be added. The first thing to do is to tell our project where the contents of this junitpdfreport essentials zip file are extracted. Add the below line with the path to your distribution location within the <project> tags of the build file.

<!-- JUnit PDF report installation location -->
<import file="E:/junitpdfreport_essentials_1_0/build-junitpdfreport.xml"/>

Step 3:

Add the below target as well to the build file so that ANT knows what to do.

<!-- PDF Report -->
<target name="pdfReport">
  <junitpdfreport todir="${junit.output.dir}" styledir="default"> 	<fileset dir="${junit.output.dir}"> 
        <include name="TEST-*.xml"/> 

Let us try to decipher this one line at a time,

1.junitpdfreport todir="${junit.output.dir}"

– This is the location where the generated pdf report will be saved.

2.fileset dir="${junit.output.dir}"

–  Provide the location where all the JUnit test results are present (Remember those XML files that were generated for each individual test executed, in the ‘TEST-*.xml’ format).

In my case, I have these test files:,, and TESTS-TestSuites.xml that are saved in the location, ‘junit/’.

Step 4:

Right-click and select ‘2 ANT Build’ and check the ‘Targets’ tab in ‘Edit Configuration’ pop-up window. Make sure the ‘pdfReport’ target is checked and it is the last target mentioned in the execution order.

PDF target configuration

Click ‘Run’ to execute the build file.

Step 5:

Verify the generated PDF report in the specified output directory (‘junit/’ in my case).

JUnit Folder

The generated PDF file had 8 pages in total. For a sample, the first 5 pages looked as below,

PDF report part 1

PDF Report part 2

Last but not the least, a snapshot of the buildfile showing HTML report and PDF report targets code,

ANT buildfile

Let us harness the power of practicing as you have reached the end of this article. See you again on another topic for you to up-skill with WebDriver!

Author avatar
Chandana Chaitanya
Lakshmi Chandana is a Software professional + passion-fueled blogger + novel-reader + artist + tutor to make your day a little brighter than it was before! She is thrilled you are here! She is on a mission to make sure learning sticks but with the fun part kept intact. She uses certain tricks called BrainBells (inspired from barbells and dumbbells used for workout) to achieve this and she says, “this is not the hardest job! As once minions said, it for sure is working in a bubble wrap factory. Imagine the self-control needed!” So, dive in to explore the fun-filled World of Learning!!

Post a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.