How to Send TestNG Reports via 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:
- First, launch the “jenkins.war” file. If not available in the system, install it.
- Now, open Jenkins (http://localhost:8080).
- Install the following Jenkins plugins if in the system:
- TestNG Results
- Email Extension
- Email Extension Template
- Selenium HTML Report
- Next, navigate to Jenkins → Manage Jenkins → Configure System → Email Notification.
- 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.
- 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.
- Do not forget to tick the “Test configuration by sending test email” box. This will help in checking the validation of the configuration.
- To validate it, enter a different email ID in the “Recipient’s email” area and click on the “Test Configuration” button.
- If the screen shows the message “Email was successfully sent”, it would mean your configuration is valid.
- 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:
- First, go to “https://myaccount.google.com”.
- Once the page opens, click on the “Security” option.
- 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.
Configuring Jenkins to Attach TestNG Reports to the Emails
To attach TestNG reports to emails:
- Navigate to Jenkins → Manage Jenkins → Configure System → Extended Email Notification.
- Once again, type “smtp.gmail.com” into the “SMTP Server” box and click on the “Advance” button.
- Now, add the configuration details you have previously entered in “Step 6” while configuring Jenkins for sending email notifications (In the previous section).
- After that, click on the “Save” option and enter the “Jenkins Dashboard”.
- Here, you can either create a new project or select any current project.
- Next, click on the “Configure” option to open a new section, now click on the “Editable Email Notifications” from the “Post-build Actions” section.
- Now, click on the “Advance” option, open the “Add Trigger” dropdown section, and choose the “Always” option.
- 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.
- In the content edit box, add the path of the emailable-report.html.
- Now, click on the “Save” option and then select the “Build Now” option to begin the execution of a job.
- Finally, go to the “Console Output” and validate the recipient mail.
Now, you are ready to share TestNG reports via email.
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?
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.