Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium电子邮件-每次测试执行时生成的旧emailable-report.html_Email_Selenium Webdriver_Email Attachments - Fatal编程技术网

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

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

在testng中执行testcase后生成旧的可发送电子邮件的报告。 这是代码供您参考

    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注释,因为您需要在执行的最后触发电子邮件代码。

尝试添加一些等待。添加等待也没有帮助。