【问题标题】:Skipped Tests are not displayed on ExtentReports跳过的测试不显示在 ExtentReports 上
【发布时间】:2021-05-16 15:17:10
【问题描述】:

范围报告中不显示跳过的测试。

我正在使用dependsonmethods,根据方法范围报告应该显示带有日志跳过的测试用例。 但它会在以前的测试用例上打印跳过日志。

   @Test(priority = 12)
void UndoRedo() {
    undoRedoCase.UndoRedoTest();
}

@Test(priority = 13)
void LockUnlock() {
    lockUnlockElement.LockUnlockCase();
}

@Test(priority = 14)
void FrameLayer() {
    layerFrame.FrameLayerCase();
}

@Test(priority = 15)
void AddImage() {
    addimage.AddImageCase();
}

@Test(priority = 16,dependsOnMethods = {"AddImage"})
void EraseImage() {
    imageErase.ImageEraseCase();
}

请查看测试执行的图片。

控制台图片 5个测试用例,失败1个,跳过1个

范围报告结果。

在以前的测试用例日志上打印的跳过的测试用例日志

跳过的测试用例不在范围报告中打印。

【问题讨论】:

    标签: testng extentreports selenium-extent-report


    【解决方案1】:

    我有一个类似的问题,但处理问题的方式不同。当我明确告诉它 test.pass() 或 test.fail() 时,有一个很好的 after 方法,但我正在努力让范围报告者捕获并记录跳过的测试。 TestNG 报告正在跳过完整的测试,希望在输出的范围内看到这一点。

        @AfterMethod
    public void getResult(ITestResult result) {
        if(result.getStatus() == ITestResult.FAILURE) {
            test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" FAILED ", ExtentColor.RED));
            test.fail(result.getThrowable());
        }
        else if(result.getStatus() == ITestResult.SUCCESS) {
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" PASSED ", ExtentColor.GREEN));
        }
        else if(result.getStatus() == ITestResult.SKIP) {
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" SKIPPED ", ExtentColor.RED));
        }
        else {
            test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" SKIPPED ", ExtentColor.ORANGE));
            test.skip(result.getThrowable());
        }
    }
    

    单个验证的示例:

    try {
        softAssert.assertEquals(plain1, plain2);
        test.pass("PASS: Field is edited");
    } catch (AssertionError e) {
        test.fail("FAIL: Field is NOT edited");
        test.fail(e);
        throw (e);
    }
    

    【讨论】:

    • 感谢分享,但我已经尝试过该代码,但不适用于我的情况。
    【解决方案2】:

    我也遇到过这个问题,下面的代码对我有用。 像这样定义 testListener,然后在 Baseclass 开始之前使用 @listeners(TestListeners.class) 在 Baseclass 中调用这个 testListener 类。

    注意:我使用过 Spark Extentreport

    public class TestListeners implements ITestListener {
    
    @override public void onTestSkipped(ITestResult result) {
    
    Baseclass.extenttest = Baseclass.extent.createTest(result.getMethod().getDescription()).assignCategory("SkipedTest");
    Baseclass.extenttest .log(Status.SKIP, result.getThrowable());
    Baseclass.extenttest .log(Status.SKIP, result.getMethod().getDescription());
    Baseclass.extenttest .log(Status.SKIP,  MarkupHelper.createLabel(result.getName(), ExtentColor.YELLOW));
    Baseclass.extent.flush();
    } }
    

    在你的测试类中定义@Test,如下所示

    @Test(description = "Test Case name", dependsOnMethods = { "Name of method on which it depends" })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-06
      • 2016-11-30
      • 2019-10-03
      相关资源
      最近更新 更多