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, ‘https://sourceforge.net/projects/junitpdfreport/files/’

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"/> 
  </fileset> 
  </junitpdfreport>
</target>

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: TEST-com.blog.junitTests.RadioBtns_Checkboxes.xml, TEST-com.blog.junitTests.SelectItems.xml, 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!

<< 10d. Advanced WebDriver – JUnit Report Customization Contd. 10f. Advanced WebDriver – Taking a Screenshot >>

Leave 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.