硒电子邮件-每次测试执行时都会生成旧的emailable-report.html

时间:2018-08-02 06:38:01

标签: email selenium-webdriver email-attachments

在testng中执行测试用例后生成旧的emailable-report。 这是供您参考的代码。

    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();
    }

请指导每次完成测试后如何生成更新的报告。

1 个答案:

答案 0 :(得分:0)

我认为您应该简单地将@AfterTest替换为@AfterSuite注释,因为您需要在执行结束时触发电子邮件代码。