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

15 Replies to “Emailable Extent Reports with Jenkins”

  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.

  2. Hi Harshit,

    Thanks a lot for detailed explanation!

    I followed all the steps you mentioned but getting below error while executing build step via jenkins. Could you please look into this. Thanks in Advance!

    Navigating to Dashboard…
    [ERROR – 2017-12-28T10:43:46.063Z] WebElementLocator – _handleLocateCommand – Element(s) NOT Found: GAVE UP. Search Stop Time: 1514457826053

    phantomjs://platform/console++.js:263 in error
    Error with XPath. Please check the XPath values
    org.openqa.selenium.NoSuchElementException: {“errorMessage”:”Unable to find element with xpath ‘//a[@view=’dashboard-view’]//i'”,”request”:{“headers”:{“Accept-Encoding”:”gzip,deflate”,”Connection”:”Keep-Alive”,”Content-Length”:”58″,”Content-Type”:”application/json; charset=utf-8″,”Host”:”localhost:10084″,”User-Agent”:”Apache-HttpClient/4.5.3 (Java/1.8.0_92)”},”httpVersion”:”1.1″,”method”:”POST”,”post”:”{\”using\”:\”xpath\”,\”value\”:\”//a[@view=’dashboard-view’]//i\”}”,”url”:”/element”,”urlParsed”:{“anchor”:””,”query”:””,”file”:”element”,”directory”:”/”,”path”:”/element”,”relative”:”/element”,”port”:””,”host”:””,”password”:””,”user”:””,”userInfo”:””,”authority”:””,”protocol”:””,”source”:”/element”,”queryKey”:{},”chunks”:[“element”]},”urlOriginal”:”/session/f2782020-ebbb-11e7-be4a-d3b3290dab9d/element”}}
    Command duration or timeout: 0 milliseconds
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:416)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:518)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:408)
    at Main.main(Main.java:44)
    Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:141)
    … 11 more
    Caused by: org.openqa.selenium.NoSuchElementException: {“errorMessage”:”Unable to find element with xpath ‘//a[@view=’dashboard-view’]//i'”,”request”:{“headers”:{“Accept-Encoding”:”gzip,deflate”,”Connection”:”Keep-Alive”,”Content-Length”:”58″,”Content-Type”:”application/json; charset=utf-8″,”Host”:”localhost:10084″,”User-Agent”:”Apache-HttpClient/4.5.3 (Java/1.8.0_92)”},”httpVersion”:”1.1″,”method”:”POST”,”post”:”{\”using\”:\”xpath\”,\”value\”:\”//a[@view=’dashboard-view’]//i\”}”,”url”:”/element”,”urlParsed”:{“anchor”:””,”query”:””,”file”:”element”,”directory”:”/”,”path”:”/element”,”relative”:”/element”,”port”:””,”host”:””,”password”:””,”user”:””,”userInfo”:””,”authority”:””,”protocol”:””,”source”:”/element”,”queryKey”:{},”chunks”:[“element”]},”urlOriginal”:”/session/f2782020-ebbb-11e7-be4a-d3b3290dab9d/element”}}
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: ‘unknown’, revision: ‘unknown’, time: ‘unknown’
    System info: host: ‘NODE320’, ip: ‘192.168.220.12’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_92’
    Driver info: driver.version: unknown

    G:\JenkinsProjectWs>exit 0

    Regards,
    Naveen

  3. Hey Naveen,

    I would recommend opening the extent report file and checking for the XPath manually. It might be the case that you are using another version of extent or your report might not be having this section.

    Regards,
    Harshit

    1. Hi Harshit, Thanks for the reply. It worked fine on windows. However I’m required to do this setup on Jenkins iOS machine. On that I getting below error. I have tried different combinations for the phantomjs path in shell command of jenkins but still unable to find path of phantomjs.exe. Could you please help. Thanks in Advance!

      “PhantomJS Exe not found on the given path – /Users/admin/Documents/JenkinsWS/phantomjs-2.1.1-macosx/bin\phantomjs.exe”

  4. Could you please tell how can we have jenkins job generating extent report as we dont have extent report plugin?

  5. I am now not certain the place you’re getting your information, however great topic. I must spend some time studying more or understanding more. Thank you for fantastic info I was in search of this info for my mission.

  6. Hi Harshit,
    Can u please clearly mentioned the arguments which i need to pass:
    1.Extent HTML Report path(testreport.html)—– I donot have any testreport.html in my project.I have ExtentReport.html in my project inside target folder/surefire-reports/ExtentReport.html(whch generates the extent report.Do you meant that file?)
    2. Destination Path where New report should be saved(I prefer workspace) —-“%WORKSPACE%\target\surefire-reports\ExtentReport.html” “%WORKSPACE%”(I have mentioned this according to my project structure is that ok?)
    3.the folder path where PhantomJS executable is present—–C:\Users\earkmaj\Desktop\learning\Selenium\Selenium_personal\Codes\EDOS_ZAIN\phantomjs-2.1.1-windows\phantomjs-2.1.1-windows\bin(i have mentioned till this path where my execuatble phantomjs is present)

    I am confused between the 1st and 2nd am i doing ok?

    Beacuse i donot find any testreport.html in my project structure

    1. Hi, I did those steps. and I can able to create emailreport.html, but when I send the mail. emailreport.html is having broken images on it. How to resolve it?

  7. Hi, I did those steps. and I can able to create emailreport.html, but when I send the mail. emailreport.html is having broken images on it. How to resolve it?

    thanks in advance

Leave a comment