4

what is the best way to send test reports as an email?

My framework has WebDriver + TestNG

user2014097
  • 41
  • 1
  • 1
  • 2

5 Answers5

4

For Jenkins..

Go to Your Project > Configure > Post-build Actions > Editable Email Notification.

Then click on Advanced Settings....

There is a box named Pre-send Script.

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

Copy that and paste it into the box. Then Save it. That will generate the colourfull page and you can send it as a report via email.

Sagor Chowdhuri
  • 233
  • 2
  • 5
2

Couple of ways, you can use jenkins to schedule your tests or run them. It gives sending emails as a post build option. Other way is, if you are using maven as a build tool, you can use plugins which send emails. mail-maven-plugin and maven postman plugin are some results on search.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
1
  1. First install "Email Extension Plugin" on your Jenkins.
  2. You need to set up SMTP server, SMTP port etc of your email provider, in your Jenkins configuration under your newly installed Email Extension Plugin section with all relevant details such as email id and password also.
  3. Now in your project configuration add this plugin in your post build actions.
  4. Add relevant email id's in your recipients list.

5. You will see a field named "Attachments"

6. In that field just enter: **/emailable-report.html

  1. It will fetch "emailable-report.html" file in your project workspace and send it as an attachment after build, depending upon your email trigger.
0

The following was helpful to me:

http://blog.qatestlab.com/2011/02/24/e-mail-distribution-of-test-results-obtained-from-selenium-testng/

DarthOpto
  • 1,640
  • 7
  • 32
  • 59
  • 1
    Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – GhostCat May 15 '17 at 14:08
0

I've created solution without Jenkins I used to Sending mail attachment using Java to sanding mail with Javamail

In TensNG annotation @AfterTest I created method to send email with attachment

EmailUtil.reportByEmail("target/surefire-reports/emailable-report.html");

and in Windows I've created batch file launchtests.bat whitch contains firstly step to run clean test, and secondly to launch one test without clean, to send previous results.

chdir C:\Users\QA\tests\tests
start /wait cmd /k "mvn clean test && exit"  /secondary /minimized
REM to send email with results in file, whitch was composed after test suite (mvn without: clean)
start /wait cmd /k "mvn test -Dgroups=FakeGroupForSendMail && exit"  /secondary /minimized

then, of course I've created tast in Windows to launch this batch every night.