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….
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.
- Use TestNG’s emailable report – This is the easiest way out as this report has plain HTML content rather than any fancy CSS.
- 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!
- 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:-
- You should have a Jenkins job that generates an Extent report in the workspace of your job.
- Take a clone of the code present at – https://github.com/kohli-harshit/extend-extent-report
- 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.
- Download PhantomJS executable from http://phantomjs.org/download.html
After prerequisites are complete, you need to do the following :-
- 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.
Categories: Awesum Stuff