Validation without skipping the test cases if one fails

739 views Asked by At

I have the following test cases:

  1. Login - Logout
  2. Login - Search - Logout
  3. Login - Search - Click on result - Logout

All these 3 testcases are considered to be independent and are within a single testNg class.

How do I validate the First test case (i.e. how to check if login is successful) ?

I have tried using assert, but when assert fails the remaining test cases (which are actually independent on the first one) will all be skipped.

How do I make sure that I validate all the test cases and irrespective of whether they pass or fail i should continue to execute all the test cases within that testNG class?

1

There are 1 answers

0
Ivan Litskevich On

It looks like you are looking for ErrorCollector. Or you can use custom SoftAssert. This is my ErrorCollector realization for JUnit:

    @Rule //collects errors without aborting test
    public ErrorCollector collector = new ErrorCollector();

    @Test
    public void SampleTest() throws Exception {

...
        try {

            // Verify label
            Assert.assertEquals("label"
                    ,driver.findElement(By.xpath("some_xpath")).getText());

        } catch (AssertionError e) {
            System.out.println("Report Error: " + e);
            collector.addError(e);
        }

...

}