I have a suite of regression tests using testng:-
<suite>
<test>
<classes>
<class name="test1"/>
<class name="test2"/>
<class name="test3"/>
<class name="test4"/>
<class name="test5"/>
</classes>
</test>
</suite>
I have a flickering test at test 3. Sometimes it throws a NoSuchElementException (these are selenium tests). The issue arises when such an exception is encountered but not when an assertion fails - in this case the suite continues.
Sometimes, the suite continues to test 4, sometimes the whole suite stops when the failure occurs.
- why is the behaviour inconsistent?
- how can I force the suite to always continue to the next test when such an exception is thrown in a given class?
Example Test Class:-
public class ItineraryViewTest extends TestBase {
@BeforeClass
@Parameters({"login", "username", "password", "userReference"})
public void addAPackage(String login, String username, String password){
if (Objects.equals(login, "true")) {
loginPage().loginWith(username, password, userReference);
}
@AfterMethod
public void closeItineraryView(){
itineraryPage().closeItineraryView();
}
@Test(description = "Tests Itinerary view can be selected")
public void itineraryViewCanBeSelected() {
itineraryPage().selectItineraryView();
assertTrue("Itinerary view was not displayed",
(itineraryPage().itineraryViewDisplayed()));
}
}
Base class:
public class TestBase
@BeforeClass
@Parameters({"env", "browser", "login", "mode", "emulatorMode"})
public void initialiseTests(String env, String browser, String login, String mode, String emulatorMode) throws MalformedURLException {
APPLICATION_LOGS.debug("Running @BeforeClass");
EnvironmentConfiguration.populate(env);
WebDriverConfigBean webDriverConfig = aWebDriverConfig()
.withBrowser(browser)
.withDeploymentEnvironment(env)
.withSeleniumMode(mode);
//new driver gets insantiated here in this openBrowser method
driver = WebDriverManager.openBrowser(webDriverConfig, getClass());
//unrelated code...
@AfterClass
public void afterClass() {
APPLICATION_LOGS.debug("Running @AfterClass");
driver.quit();
}
@AfterSuite()
public void afterSuite() {
APPLICATION_LOGS.debug("Running @AfterSuite");
extent.flush();
}