-1

I have tried using the TestNG reporting(target/surefire-reports/emailable-report.html) but did not like it. Can anyone suggest how to get testcase names along with build details in Jenkins email body and not as an attachment.

1 Answers1

0

To include some HTML file content to the email body instead of an attachment, add to email body:

${FILE,path="target/surefire-reports/emailable-report.html"}

If you don't like emailable-report you can generate the custom report with required data, implementing the TestNG Listener interface. But its not trivial, see example:

https://www.seleniumeasy.com/testng-tutorials/testng-customize-emailable-html-report-example.

Also, you might use another report template, provided by

Email Extension Jenkins plugin.

If you like it, just add this line to the email body:

${JELLY_SCRIPT,template="html"}
Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14
  • I have tried the 1st option previously and did not like the UI of the email. The last option is interesting. Apart from these is there a clean way to get the testcase name followed by results in the email body? TestcaseName | Pass/Fail Click on the testcase link and we could get the logs/screenshots? – Juhi Sehgal Feb 03 '22 at 14:40
  • I've googled a lot, trying to research. But no other ready solutions were found, just JELLY_SCRIPT script template seems to have some access to the test results. Try to look at this template: https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/html.jelly There are some references to test objects: like `${it.JUnitTestResult}` which returns `List`. [TestResult.java](https://github.com/jenkinsci/junit-plugin/blob/master/src/main/java/hudson/tasks/junit/TestResult.java) – Max Daroshchanka Feb 03 '22 at 14:53
  • So I think it's possible to create a custom `.jelly` report and access the data from `TestResult.java` class. But I've not tested this... – Max Daroshchanka Feb 03 '22 at 14:53
  • @JuhiSehgal if you define jobs Jenkinsfile groovy pipiline, you can try suggestions from this https://stackoverflow.com/questions/64025694/jenkins-display-names-of-failed-tests-testng – Max Daroshchanka Feb 03 '22 at 15:10
  • @JuhiSehgal and this https://stackoverflow.com/questions/38978295/using-pipeline-groovy-how-can-i-extract-test-results-from-jenkins-for-my-curr – Max Daroshchanka Feb 03 '22 at 15:12