How to Send TestNG Reports via Email?

  • Updated on December 22, 2023
  • Email

If you’re working in a software development and testing company that works with Java applications, you probably know about TestNG.

It’s an open-source test automation framework that is often used for test reporting with Tesults, Selenium, Katalon TestOps, and a few other prominent automation testing platforms to make test execution and operation more efficient.

Software testing is a method of checking if the product developed is meeting the requirements or not. Every SaaS company knows the benefits of software testing.   

However, the real problem shows up when we try to share the TestNG reports with others via mail.

Not many platforms offer a default option for sharing the TestNG reports without putting in hours of hard work and digging into long strings of codes.

Today, we will discuss how to send TestNG reports via email for Jenkins Selenium tests, where you don’t have to deal with a lot of codes.

Let’s dig in.

Steps to Share TestNG Reports via Email

You have the TestNG reports ready, created using Jenkins. Now, you need to send the results to other team members, managers, and relevant stakeholders. 

But before moving any further, you must configure Jenkins to send emails containing the TestNG reports.

Configure Jenkins to Send Email Notifications of the TestNG Reports

Follow the steps mentioned below to configure the necessary setup to share the testing reports:

  1. First, launch the “jenkins.war” file. If not available in the system, install it.
  2. Now, open Jenkins (http://localhost:8080).
  3. Install the following Jenkins plugins if in the system:
    1. TestNG Results
    2. Email Extension
    3. Email Extension Template
    4. Selenium HTML Report
  4. Next, navigate to Jenkins → Manage Jenkins → Configure System → Email Notification.
  5. Once you get to the new page, enter the email ID in the “SMTP Server” box. For example, the SMTP email ID would be “smtp.gmail.com” in Gmail.
  6. After that, click on the “Advance” button to go to the next page, where you have to add the correct information to ensure if mail configuration is valid. Please note that while adding the info, the user needs to add an “Email ID” in the “User Name” section. The email ID should be the one you will be sending the emails of the test reports.
  7. Do not forget to tick the “Test configuration by sending test email” box. This will help in checking the validation of the configuration.
  8. To validate it, enter a different email ID in the “Recipient’s email” area and click on the “Test Configuration” button.
    1. If the screen shows the message “Email was successfully sent”, it would mean your configuration is valid.
    2. If you send a message saying there’s an error, either your configuration has flaws or has security access issues. For incorrect configuration issues, you just need to recheck your configuration data and remove the invalid information. To fix security access issues, follow the steps mentioned below:
      1. First, go to “https://myaccount.google.com”.
      2. Once the page opens, click on the “Security” option.
      3. Next, enter the “less secure app access” page and switch on the “less secure app access” option.

Congratulations! You are all set to send email notifications of  TestNG reports.

Myths About Software Testing There is a myth among programmers that automatic testing is more efficient than manual testing and all tests should be automated. But in reality, the repetitive tests should be automated, and the research tests should be done manually because it minimizes the cost. In short, both tests work effectively in particular situations. 

Software testing Image

Configuring Jenkins to Attach TestNG Reports to the Emails

To attach TestNG reports to emails:

  1. Navigate to Jenkins → Manage Jenkins → Configure System → Extended Email Notification.
  2. Once again, type “smtp.gmail.com” into the “SMTP Server” box and click on the “Advance” button.
  3. Now, add the configuration details you have previously entered in “Step 6” while configuring Jenkins for sending email notifications (In the previous section).
  4. After that, click on the “Save” option and enter the “Jenkins Dashboard”.
  5. Here, you can either create a new project or select any current project.
  6. Next, click on the “Configure” option to open a new section, now click on the “Editable Email Notifications” from the “Post-build Actions” section.
  7. Now, click on the “Advance” option, open the “Add Trigger” dropdown section, and choose the “Always” option.
  8. Click on the “Advanced” option. On the next page, fill in the relevant details. For example, filling in the list of recipients with relevant mail addresses.
  9. In the content edit box, add the path of the emailable-report.html.
  10.  Now, click on the “Save” option and then select the “Build Now” option to begin the execution of a job.
  11.  Finally, go to the “Console Output” and validate the recipient mail.

Now, you are ready to share TestNG reports via email.

Final Thoughts

There you go! Now, you are all set to send TestNG reports via email in Jenkins to all the relevant stakeholders. Every time a user creates a TestNG test execution report in Jenkins Selenium, all the recipients will get an email notification with an attached test report.

If programmers want to change email recipients or any other TestNG report-related changes, They can go to the Jenkins dashboard to reconfigure it.

Do you prefer Maven over Jenkins for sending TestNG reports via email?

No worries!

As long as you have the relevant coding knowledge, you can also configure Maven to send TestNG reports to the team using email.

Consult your software testing team to choose the right option for sending TestNG report emails.




Share

Related Post