Awesum Stuff

Emailable Extent Reports with Jenkins

Many people including me swear by the sheer awesomeness of Extent reports! The fact that it’s community edition is able to provide a more than presentable HTML Test execution report is great and it helps in quickly setting up a reporting mechanism for your Tests.

We all love Jenkins pipelines, don’t we ? So I was setting up a Jenkins job that needs to send an email-report once it finishes….

THE PROBLEM:-

When we use the Extent HTML report as part of the Jenkins job’s report Email’s content (with the help of the Email extension plugin), the report turns up without any CSS. The reason is that Outlook doesn’t support CSS in the Email content.

THE SOLUTION:-

  1. Use TestNG’s emailable report – This is the easiest way out as this report has plain HTML content rather than any fancy CSS.
  2. Attach the Extent report as an attachment rather than the Email’s content – This works but I don’t want my recipients to click to the open the report and then view it. After all, time is money!
  3. Hack into Extent’s HTML report and create a new email-able one that puts important info into the email body.

I implemented option 3 after not being satisfied from the previous 2. So, following are the steps that need to be done in order to send the extent report as part of your report email’s content:-

Prerequisites :-

  1. You should have a Jenkins job that generates an Extent report in the workspace of your job.
  2. Take a clone of the code present at – https://github.com/kohli-harshit/extend-extent-report
  3. Provided you have maven installed, if you navigate to the directory where pom.xml resides and execute the Maven command – “mvn package”, this should create a JAR file with dependencies in the target folder.
  4. Download PhantomJS executable from http://phantomjs.org/download.html

After prerequisites are complete, you need to do the following :-

  1. Add a build step in your job which calls the generated JAR file with the parameters – Extent HTML Report path(testreport.html), Destination Path where New report should be saved(I prefer workspace) and the folder path where PhantomJS executable is present. The build step should look something like:-

The output of the above command should be that a file named emailreport.html should be created in the workspace of your Jenkins job. The difference between this file and the default testreport.html is that instead of having data inside the html, it has snapshots(to preserve the look and feel as we can’t do it with CSS).

2.Install the Email-ext plugin on your Jenkins server.

3. Add a PostBuild step by selecting Editable Email Notification and configure the email body like:-

The trick here is that the Java code that we ran opens the default extent report with PhantomJS headless browser, takes snapshots of the key sections and put the png files in the workspace of the Jenkins job. The Email notification plugin attaches the PNG files created with the email and they are displayed inside the content of the Email as we gave the newly created HTML in the email body.

Here’s a comparison with TestNG emailable reports:-

Sample Report available here.

Happy Automating!

Harshit Kohli

Advertisements

2 replies »

  1. Please share a sample HTML output file as well.

    Since there is a dependency of Phantom Js , its tough in our environment to install due to so many permission required again. Anyway great effort.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s