【问题标题】:How can I add skipped test cases in ExtentReports?如何在 ExtentReports 中添加跳过的测试用例?
【发布时间】:2018-08-02 17:35:21
【问题描述】:

我需要将所有跳过的测试用例添加到我的 ExtentReports。我怎样才能做到这一点?

我在 BaseTest.java 中尝试过以下代码:

@AfterMethod
public void afterMethod(Method method)
{
    if (result.getStatus() == ITestResult.FAILURE) 
    {
        ((ExtentTest) extentTest.getTest()).log(LogStatus.FAIL, result.getThrowable());
    } 
    else
        if (result.getStatus() == ITestResult.SKIP)
        {
            ((ExtentTest) extentTest.getTest()).log(LogStatus.SKIP, "Test skipped " + result.getThrowable());
        }
        else 
        {
            ((ExtentTest) extentTest.getTest()).log(LogStatus.PASS, "Test passed");
        }

    report.endTest(extentTest);
    report.flush(); 
}

【问题讨论】:

  • 问题需要进行分类,以便引起能够回答的人的注意(Java)
  • 我试过下面的代码:你的尝试结果是什么?您有任何可以与我们分享的错误消息吗?

标签: java selenium extentreports


【解决方案1】:

尝试实现 ITestListener 和以下方法:

  public interface ITestListener extends ITestNGListener {

  void onTestStart(ITestResult result);

  public void onTestSuccess(ITestResult result);

  public void onTestFailure(ITestResult result);

  public void onTestSkipped(ITestResult result);

  public void onTestFailedButWithinSuccessPercentage(ITestResult result);

  public void onStart(ITestContext context);

  public void onFinish(ITestContext context);

}

所以实现看起来像这样:

public class test implements ITestListener {

    @Override
    public void onTestSkipped(ITestResult result) {
        ... do Your stuff for skip tests extent report here ...
    }

    @Override
    public void onTestSuccess(ITestResult result) {
        ... do Your stuff for passed test extent report here ...
    }

    ... and all other methods are automatically implemented, and You don't have to check status, test will automatically enter proper methods. 


    @Override
    public void onStart(ITestContext context){
          //init extent reports... on whatever way You do it...
    }


    @Override
    public void onFinish(ITestContext context){
        report.endTest(extentTest);
        report.flush(); 
    }

}

这适用于所有测试。

希望对你有帮助,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 2011-07-21
    相关资源
    最近更新 更多