我要做的是:
在测试执行完成后生成测试报告,然后通过电子邮件发送(我使用的是Maven,黄瓜和RestAssured)。
我面临的问题:
上述所有内容都在发生,除了通过电子邮件发送的测试报告实际上来自之前的测试执行。也就是说,当通过电子邮件发送报告的代码运行时,报告或包含该报告的文件夹不会刷新。
有没有办法在测试执行结束时通过maven刷新文件夹,还是有其他方法可以发送最新的测试报告..?
非常感谢任何指针。下面是我的Cucumber跑步者代码,
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/Feature"
,glue= "com/sss/tests/RestApi"
,tags = {"@TestInDevelopment"}
,plugin = {"com.cucumber.listener.ExtentCucumberFormatter:/Report.html"}
,format = {"pretty","html:target/cucumber"}
,monochrome = true
)
public class TestRunner {
static Configurations config = new Configurations();
@BeforeClass
public static void setup(){
/*
* Loading the log4j configurations, before the start of test execution
*/
String folderName = "PropertyFiles";
String fileName = "log4j.properties";
PropertyConfigurator.configure(config.getResourcePath(folderName)+fileName);
}
@AfterClass
public static void teardown() throws UnknownHostException, IOException, InterruptedException {
/*
* Loading the configuration file for the test execution report and setting up the user name, OS info and host details in the report
*/
Reporter.loadXMLConfig(new File(config.getResourcePath("Resources")+"extent-config.xml"));
Reporter.setSystemInfo("USER", System.getProperty("user.name"));
Reporter.setSystemInfo("OS", System.getProperty("os.name"));
Reporter.setSystemInfo("HOST NAME", InetAddress.getLocalHost().getHostName());
/*
* After the test execution is completed, parsing the generated test execution report to to see if there is any failures and based on that,
* sending the Build Success/Failure e-mail to the configured mail list
*/
HTML_TestExecutionReportParser testExecutionStatusParser = new HTML_TestExecutionReportParser();
TestExecutionReportEmailSender testExecutionReportMailSender = new TestExecutionReportEmailSender();
testExecutionReportMailSender.sendTestExecutionReportEmail(testExecutionStatusParser.isAssertionFailureFound(), testExecutionStatusParser.errorsFoundList());
}
}
答案 0 :(得分:3)
您可以尝试将电子邮件地址代码放在JVM shutdown hook
中。因此,当每个其他过程完成时,它将被调用。
关闭挂钩示例 - https://www.geeksforgeeks.org/jvm-shutdown-hook-java/