To email an Extent Report generated by Selenium WebDriver, you can use the following steps:
- Generate the Extent Report using Selenium WebDriver and save it to a local directory.
- Use a Java email library, such as apache commons mail, to create an email message.
- Attach the Extent Report file to the email message using the attachment functionality provided by the email library.
- Specify the recipient's email address, subject, and body of the email message.
- Use an email provider like Gmail or Yahoo to send the email message.
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("C:\\Users\\arili\\git\\Assignments\\Selenium\\target\\tutu.html");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription(" Test Execution Report");
attachment.setName("Report.html");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("smtp.gmail.com");
email.setSSLOnConnect(true);
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("your email", "authentication_code"));
email.addTo("toemail", "Test");
email.setFrom("from email", "Me");
email.setSubject("Automation Test Execution Report");
email.setMsg("Automation Test Execution Report");
email.attach(attachment);
email.send();
- First, we use the apache commons mail library and set the path of the extent report.
- Then we put the description and then used the multipart email library.
- Here we set the SMTP port and other Gmail authentication tokens and emails.
- Set the from mail and to mail accordingly.
- Finally, attach the attachment and send the mail.
Conclusion:
This is a simple and effective way of sending a freshly generated extent report through mail.