【问题标题】:TestNG - emailable-report issueTestNG - 电子邮件报告问题
【发布时间】:2015-07-06 03:19:04
【问题描述】:

我已经创建了发送邮件的 java 方法和附加 TestNG emailable-report 的邮件。邮件和报告正在发送到指定的电子邮件地址。

我的问题是我最后调用 sendmail 方法意味着当所有其他测试都完成时,但问题是我总是在邮件中收到上一个报告。那么它就像所有类执行后的TestNG更新报告吗?

我想在邮件中获取最新的电子邮件报告,而不是以前的最后一个电子邮件报告。我该怎么做?

【问题讨论】:

    标签: email selenium-webdriver testng


    【解决方案1】:

    我想在邮件中获取最新的电子邮件报告,而不是以前的 最后一个电子邮件报告.. 我该怎么做?

    我认为..您在@aftersuite 中发送邮件。您将收到以前的测试电子邮件报告,因为测试当前正在运行,并且只有在完成时才会生成报告。

    我会建议您使用像 jenkins 这样的持续集成服务器,因为它提供了发送电子邮件作为构建后选项或构建工具(如 Maven 或 ant)来运行您的测试,然后有一个测试后事件以通过电子邮件发送结果。Maven 也提供了许多插件来在测试执行后自动发送邮件,如 Postman 邮件插件

    另一种解决方案:如果您不愿意使用持续集成服务器(jenkins)或 maven 或 ant

    TestNG IReporter 监听器

    通过将你的类实现到IReporter接口来创建你自己的CustomReport。这个接口只有一个方法来实现generateReport。该方法在 List 中包含了完整测试执行的所有信息,我们可以使用它生成报告。

    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 
        }
        }
        }
        }
    

    希望这对您有所帮助...如果您需要任何进一步的帮助,请回来

    【讨论】:

    • 所以如果我使用 TestNG IReporter 监听器意味着我不能使用该电子邮件报告,需要创建自定义报告,对吧?
    • @Helping Hands 是的,您需要像上面那样创建一个 CustomReporter 类
    • 很高兴能帮上忙 :)
    【解决方案2】:

    对于 Windows 操作系统,我最后在 @AfterSuite 中创建了(用于 TestNG),通过 2 个步骤发送带有附件和批处理文件的邮件。第一步启动 mvn clean test 以执行所有测试而没有先前的结果。第二步启动测试没有参数 clean 并在不存在的组上运行:) 批处理位于包含测试的文件夹中。

    start /wait cmd /k "mvn clean test && exit"  /secondary /minimized
    REM to send email with results in file, whitch was composed after test suite (mvn without: clean)
    start /wait cmd /k "mvn test -Dgroups=PhantomGroupNonExist && exit" /secondary /minimized
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 2012-06-23
      • 2013-02-18
      • 2019-11-21
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多