Selenium电子邮件-每次测试执行时生成的旧emailable-report.html
在testng中执行testcase后生成旧的可发送电子邮件的报告。 这是代码供您参考Selenium电子邮件-每次测试执行时生成的旧emailable-report.html,email,selenium-webdriver,email-attachments,Email,Selenium Webdriver,Email Attachments,在testng中执行testcase后生成旧的可发送电子邮件的报告。 这是代码供您参考 public void EmailFunction() { try { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(".\\test-output\\emailable-report.html"); attachmen
public void EmailFunction() {
try {
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(".\\test-output\\emailable-report.html");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Test Report Logs");
attachment.setName("Report.html");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator(MyEmail, MyPassword));
email.setSSLOnConnect(true);
email.setFrom(MyEmail, "Faizan Mamji");
email.addCc("abc@test.com");
email.setSubject("Report Logs");
email.setMsg("Please find attached logs!");
email.addTo(MyEmail, "Faizan Mamji");
// add the attachment
email.attach(attachment);
// send the email
email.send();
}
catch (Exception ex) {
ex.getMessage();
Assert.fail("Email failed to send");
}
}
@AfterTest
public void afterTest() {
TestExecutionEmail ObjEmail= new TestExecutionEmail(maindriver);
maindriver.quit();
ObjEmail.EmailFunction();
}
请指导如何在每次完成测试执行后生成更新的报告。我认为您应该简单地将@AfterTest替换为@AfterSuite注释,因为您需要在执行的最后触发电子邮件代码。尝试添加一些等待。添加等待也没有帮助。