TestNG-可通过电子邮件发送报告 [英] TestNG - emailable-report issue
问题描述
我创建了java方法来发送邮件,并且该邮件附加了TestNG emailable-report.邮件和报告可以很好地发送到指定的电子邮件地址.
I have created java method to send mail and that mail attaching TestNG emailable-report. Mail and report is sending fine to specified email address.
我的问题是,当所有其他测试完成时,我最终要调用sendmail方法,但问题是我总是在邮件中获取先前的最后一个报告.就像所有类执行完后的TestNG更新报告一样吗?
My issue is I am calling sendmail method at last means when all other tests complete but thing is I am always getting previous last report in mail. So is it like TestNG update report after all class execution?
我想获得邮件中的最新可电子邮件发送的报告,而不是以前的最后一个可电子邮件发送的报告.我该怎么做?
I want to get latest emailable-report in mail rather than previous last emailable-report.. How can I do that?
推荐答案
我想获得邮件的最新可电邮报告,而不是以前的 最后的电子邮件报告.我该怎么办?
I want to get latest emailable-report in mail rather than previous last emailable-report.. How can I do that?
我认为..您正在通过@aftersuite
发送邮件.由于该测试当前正在运行,并且只有在测试完成时才会生成报告,因此您会收到以前的可通过电子邮件发送的测试报告.
I think..you're sending mail in your @aftersuite
.You're getting previous test emailable-report because the test is currently running and only when it finishes reports will be generated.
我建议您使用诸如jenkins之类的连续集成服务器,因为它可以将发送电子邮件作为后期构建选项或诸如Maven或ant之类的构建工具来运行测试,然后具有一个后期测试事件以通过电子邮件发送结果.提供了许多插件,可以在测试执行后自动发送邮件,例如Postman邮件插件
I will suggest you to use a continuous Integration server like jenkins because it gives sending emails as a post build option or build tool like Maven or ant to run your tests, then have a post test event to email the results.Maven also provides many plugins to automatically send mails after test execution like Postman mail plugin
另一种解决方案:如果您不愿意使用连续的集成服务器(jenkins)或maven或ant
Another solution : If you are not willing to use a continuous Integration server(jenkins) or maven or ant
TestNG IReporter侦听器
通过将您的类实现为IReporter
接口来创建自己的CustomReport.此接口只有一种方法可以实现generateReport.此方法在列表中具有完整测试执行的所有信息,我们可以使用它生成报告.
Create your own CustomReport by implementing your class to IReporter
Interface.This interface has only one method to implement generateReport. This method has all the information of a complete test execution in the List and we can generate report using it.
public class CustomReporter implements IReporter{
@Override
public void generateReport(List<XmlSuite> arg0, List<ISuite> arg1,
String outputDirectory) {
// Second parameter of this method ISuite will contain all the suite executed.
for (ISuite iSuite : arg1) {
//Get a map of result of a single suite at a time
Map<String,ISuiteResult> results = iSuite.getResults();
//Get the key of the result map
Set<String> keys = results.keySet();
//Go to each map value one by one
for (String key : keys) {
//The Context object of current result
ITestContext context = results.get(key).getTestContext();
//results of all the test case will be stored in the context object
//Ex: context.getFailedTests(); will give all failed tests and similarly you can get passed and skipped test results make your own html report using the above data
}
}
}
}
希望这对您有帮助...如果您需要其他帮助,请尽快回来
Hope this helps you...Kindly get back if you need any further help
这篇关于TestNG-可通过电子邮件发送报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!