0

目前我正在使用 selenium 测试 ng 和报告我正在使用 extendreports 框架进行报告。在我的情况下一切工作正常。我面临的问题都是我的测试用例显示通过它没有显示失败。

  @BeforeTest
public void setUp()
{
    //where we need to generate the report
    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyReport.html");
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);

    // Set our document title, theme etc..
    htmlReporter.config().setDocumentTitle("My Test Report");
    htmlReporter.config().setReportName("Test Report");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setTheme(Theme.DARK); 

}




 @Test
public void On_Page_IM() throws InterruptedException {
      test = extent.createTest("On_Page_IM");
    wd.manage().window().maximize();

    Thread.sleep(10000);

    test.log(Status.INFO,"On page intent media: Show");

}

   @AfterSuite
public void tearDown()
{
    extent.flush();
    wd.quit();
}

@Aftermethod

4

2 回答 2

0

添加此代码后,它解决了

   @AfterMethod
public void getResult(ITestResult result)
{
    if(result.getStatus()==ITestResult.FAILURE)
    {
        test.log(Status.FAIL, result.getThrowable());

    }
   // extent.endTest(test);
}
于 2017-08-31T09:34:03.820 回答
0

只需在测试结束时添加以下代码

@AfterMethod
public void AfterMethod(ITestResult result) {

    if (result.getStatus() == ITestResult.FAILURE) {
        test.log(Status.FAIL,
                MarkupHelper.createLabel(result.getName()
                        + " Test case FAILED due to below issues:",
                        ExtentColor.RED));
        test.fail(result.getThrowable());
    } else if (result.getStatus() == ITestResult.SUCCESS) {
        test.log(
                Status.PASS,
                MarkupHelper.createLabel(result.getName()
                        + " Test Case PASSED", ExtentColor.GREEN));
    } else {
        test.log(
                Status.SKIP,
                MarkupHelper.createLabel(result.getName()
                        + " Test Case SKIPPED", ExtentColor.ORANGE));
        test.skip(result.getThrowable());
    }
}

@AfterTest
public void AfterTest() {

    extent.flush();

}
于 2019-05-28T10:05:33.317 回答