如果由于NoSuchElementException或任何其他异常导致测试失败,则范围报告未标记我的测试失败

时间:2019-05-28 08:03:21

标签: testng selenium-extent-report

我已经使用了扩展报告来生成HTML报告,我正在使用一个测试框架。我只有一门课,并提到了@Test测试方法下的所有测试。现在,如果我的任何测试都抛出NoSuchElementException,那么在范围报告中以及在测试构建状态中,都应将其标记为FAIL,对于此失败的测试,应该出现失败的测试计数。

我对每个测试都使用try catch,而在catch中尝试使用下面的方法 test.fail(e); 程度上.flush();

我希望范围报告应将失败的测试显示为FAIL,并且测试构建状态应显示失败的测试计数。

但是它并没有发生

1 个答案:

答案 0 :(得分:0)

I found the answer and thus posting it.
Use below code in all tests...you must include all test in try catch 

catch (AssertionError e) 
{
            test.fail(e);
            Assert.fail();
            extent.flush();
}

after this any kind of exception that comes in between steps of tests will be caught in catch and then this test.fail will tell extent report to mark that test as FAIL and this Assert.fail() will test TestNG to mark that test as FAIL.

Do include AssertionError in catch block as that is the key which worked for me