Thursday, July 20, 2017

How to email Selenium results reports using Jenkins?

In the previous post we have seen sending an e-mail notification when the build/tests failed. That email notification doesn’t provide us with details of Passed/Failed tests.

To get full details about the execution results, we have to use Email Extension Plugin in Jenkins.We can email the results reports that are generated in Jenkins. With which you can directly check how many tests Passed? How many failed?

I have taken three simple testng tests as shown in the below screen shot. Two of them will Pass and the other one fails.



When executed the above tests using TestN a result report "emailable-report.html" is generated under test-output folder in project home directory as show below.


Now we have to email this report from Jenkins to all the team members after test execution. Let’s get with no further due…

If you have any queries on creating testng tests and batch file please refer my previous post How to execute Selenium Test Cases from Command Prompt in TestNG?

Step 1: Installing Email Extension Plugin. Launch Jenkins-> click Manage Jenkins-> click on Install Plugins.

Step 2: In the Plugins Manager, Under Available tab-> Search for Email Extension-> Select Email Extension Plugin and click on Install without restart.


Wait for plugin to get installed for few minutes. After Installation the plugin should be available under Installed tab.


Step 3: Once the plugin installed. You need configure email in two sections Extended E-mail Notification and E-mail Notification.

Go to Mange Jenkins-> Configure System. Please enter your details as shown in the below screen shots. In the both places you need to enter same email id and password.

And from this account the emails will be sent. In my case from "seleniumbabuqa@gmail.com" the emails will be sent.



Step 4: Now create Job to run the tests. Manage Jenkins-> New Item-> Enter Project title emailReportsDemo-> Click OK.


Step 5: Configure the tests that needs be executed.  Enter project home directory in Use custom workspace and batch file name in the Build section as shown below.




Step 6: Go to Post Build Actions and select Editable Email Notification. This option only available if Email Extension Plugin installed.


Step 7: Under Editable Email Notification section enter Recipients emails, select Content type and Click on Apply.


Step 8: Click on the Advenced Settings... button. And select Always option from Add Trigger drop down list. Which means Jenkins will trigger email every time the tests executed.


Step 9: To attach the content of the report "emailable-report.html" in the email body add the below code in "Pre-send Script" field. The below code gets the path of the report and it's content.

           def reportPath = build.getWorkspace().child("test-output/emailable-report.html")
           msg.setContent(reportPath.readToString(), "text/html");


Step 10: Click Apply and Save. We are don with configuration of Email and Tests in Jenkins. Now click on Build Now in the job created.


 Check whether emails are received or not with reports in the email body.


That's it guys, we did it. Hope this post is helpful to you, please share it with your friends. Thanks!!

#HappyLearning #HappyTesting

36 comments:

  1. Brother i need configuration of selenium webdriver with python and jenkins.
    means after my selenium script run email should be sent to my email address can you write a blog on this

    ReplyDelete
    Replies
    1. What you want to send in email? Did you try configuring email? facing issues?

      Delete
  2. Hi, thank you for this explanation. I have an issue however with the emailable-report.html that is being sent. It is the previous test run result. I cannot figure out right now why this is happening. Any ideas you can offer?

    ReplyDelete
    Replies
    1. Update: ok so I changed my report path to be: target/surefire-reports/emailable-report.html but I'm not sure if that was the issue because I believe I had tried that path before. Its working now however. Perhaps the problem was due to having the testNG.xml report open while executing tests? not sure but its working ;)

      Delete
  3. Hi,
    For me build.getWorkspace().child("test-output/emailable-report.html") path is pointing to C:\Program Files (x86)\Jenkins\workspace\project folder.
    But inside floder doesn't have any files/folders.

    Can you please help on this

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. I had the same problem
      You should set your custom workspace
      Go to configuration of your job
      Build section
      Click on the "Advanced" button
      Set "Use custom workspace" ckrckbox
      Set path to your project folder

      see screenshot
      https://www.screencast.com/t/7KLLz741YJL

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi Venkat, I tried with outlook, but no success. Do I need to change the configuration for outlook different than gmail?

    ReplyDelete
    Replies
    1. Yes you have to. Sorry for the late reply.

      Delete
    2. Hi i have done the same configuration,it is running in the jenkins but chrome browser will not opened it will be running in background or headless like browser

      Delete
  6. Hi.. I am using editable email plugin and I have custom HTML report to send. But the issue I am facing is that the html content lack the styling when I email it. Not sure how to resolve the issue.

    ReplyDelete
  7. Third party processors are used and various technologies applied to identify dead or closed email accounts without sending any mails to them.email verification

    ReplyDelete
  8. If you are not working on building your email list already, then stick with this article till the end because I'm going to share 16 ways to grow your email list.
    email fraud Huntington Beach

    ReplyDelete
  9. Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. ethereum notifications

    ReplyDelete
  10. If you think email verification is a one trick game, then you could not have been further from the truth.email cleaning

    ReplyDelete
  11. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. www.hotmail.com

    ReplyDelete
  12. Thanks a lot for massive hard work , very nice article. hotmail.com

    ReplyDelete
  13. what if i have more than one HTML, in that case how i am supposed to configure 2 customized HTML report file?

    ReplyDelete
  14. So, people may notice you from videos. You can also add offers and email sign-up cards & annotations on your videos. While watching your videos people notice this annotations and cards. Email List for Marketing

    ReplyDelete
  15. Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. ActveCampaign Support

    ReplyDelete
  16. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.
    email search

    ReplyDelete
  17. A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. como abrir correo hotmail

    ReplyDelete
  18. Hi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job! hotmail-inicio-sesion.com

    ReplyDelete
  19. I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. https://hotmail-account.email

    ReplyDelete
  20. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... make money

    ReplyDelete
  21. Thank you for taking the time to publish this information very useful! https://45.77.247.58/

    ReplyDelete
  22. Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. bulk extractor email

    ReplyDelete
  23. I am thankful to you for sharing this plethora of useful information. I found this resource utmost beneficial for me. Thanks a lot for hard work. free bulk email accounts

    ReplyDelete
  24. Thanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC. how to send 100 emails at once

    ReplyDelete
  25. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. Email List Collection

    ReplyDelete
  26. I would like to say that this blog really convinced me to do it! Thanks, very good post. judi online

    ReplyDelete
  27. This is a decent post. This post gives really quality data. I'm unquestionably going to investigate it. Truly exceptionally valuable tips are given here. Much obliged to you to such an extent. Keep up the acts of kindness. domino 105

    ReplyDelete
  28. Buy Gmail PVA Accounts from our company because we have the best experts in the markeet who create accounts with different USA Ips Buy Aged Instagram Accounts

    ReplyDelete

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...