Selenium扩展报告框架不会生成失败状态

时间:2017-08-31 07:49:39

标签: selenium testing selenium-webdriver selenium-extent-report

目前我正在使用selenium test 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

2 个答案:

答案 0 :(得分:0)

添加此代码后解决了

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

    }
   // extent.endTest(test);
}

答案 1 :(得分: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();

}