Reputation: 21
I am using TestNG with Selenium WebDriver, the framework that I use has one base class which has BeforeClass method and all the Suite classes extend from this base class and have overriden BeforeClass methods as shown.
public BaseClass{
@BeforeClass
public void preConditions{
//primary actions like opening browser and setting preferences
}
}
public TestSuiteClass extends BaseClass{
@BeforeClass
@Override
public void preConditions(){
super.preCnditions();
//specific preconditions required by test suite
}
}
The problem I am have is, if an overridden method is failing for any reason, all the test suits/cases gets skipped and entire test execution stops. How to stop this from happening?
Upvotes: 0
Views: 983
Reputation: 11
If something fails in @Before... annotated procedure the tests will be skipped instead of failing, because the problem is not with your test cases, but with the process before them. So it looks like your car cannot cross the river on a broken bridge, but it's not your car's fault.
If you really want to do some hacking about it, you can find ideas here!
Upvotes: 1
Reputation: 50809
You can find a way around this, but you need to consider if you realy want to do it. The idea of the method with @BeforeClass
annotation is to set relevant data for the test (you even called it preConditions
). If it fails, the test won't pass anyway.
One way to do it is to remove the @BeforeClass
annotation and call the method from the test itself
public TestSuiteClass etends BaseClass {
public void customPreConditions() {
super.preCnditions();
}
@Test
publuc void someTest() {
customPreConditions();
// do the test
}
}
The test will continue even if customPreConditions()
is not successful.
Upvotes: 0