Execution of Selenium Script even after Test case fails Execution of Selenium Script even after Test case fails selenium selenium

Execution of Selenium Script even after Test case fails


Using the alwaysRun = true annotation in TestNG is not going to entirely solve your problem.

In order to allow Selenium to continue even when there is an occasional Exception, you need to define a Wait object with the FluentWait class, like so:

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)       .withTimeout(30, SECONDS)       .pollingEvery(5, SECONDS)       .ignoring( NoSuchElementException.class, ElementNotFoundException.class );// using a customized expected conditionWebElement foo1 = wait.until(new Function<WebDriver, WebElement>() {     public WebElement apply( WebDriver driver ) {       // do something here if you want       return driver.findElement( By.id("foo") );     }   });// using a built-in expected conditionWebElement foo2 = wait.until( ExpectedConditions.visibilityOfElementLocated(     By.id("foo") );

This gives you the ability to ignore exceptions whenever .findElement is called until a certain pre-configured timeout is reached.


Ok, in that case you need to use one of the attribute of @Test Annotation i.e

@Test(alwaysRun = true)

If set to true, this test method will always be run even if it depends on a method that failed.