com.version1.webdriver.utils.TolerantExceptionHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-java-test-automation Show documentation
Show all versions of selenium-java-test-automation Show documentation
A simple Selenium framework offering externalised configuration, a good selection of libraries for supporting
test data, simple WebDriver browser binary resolution and an opinionated approach for WebDriver test design.
The newest version!
package com.version1.webdriver.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class TolerantExceptionHandler {
private List tolerantExceptions;
private Logger logger = LoggerFactory.getLogger(TolerantInteraction.class);
public TolerantExceptionHandler(List tolerantExceptions) {
this.tolerantExceptions = tolerantExceptions;
}
public TolerantExceptionHandler(List tolerantExceptions, Logger logger) {
this(tolerantExceptions);
this.logger = logger;
}
/**
* Checks an input exception against a predefined list of tolerant exceptions. It either:
*
* - returns the exception (if it's on the tolerant list) or
* - throws the exception if it's not on the tolerant list.
*
* @param throwable the throwable that needs to be handled
* @return the input exception if is on the tolerant exceptions list
* @throws Throwable the input exception if it's not on the tolerant exceptions list
*/
public Throwable propagateIfNotIgnored(Throwable throwable) throws Throwable {
for (String tolerantExceptionClassName : tolerantExceptions) {
if (isInstanceOf(tolerantExceptionClassName, throwable)) {
logger.info("Exception {} will be ignored", tolerantExceptionClassName);
return throwable;
} else {
logger.error("Un-tolerated Exception {} encountered during tolerant action attempt", throwable.getClass().getName());
}
}
throw throwable;
}
private boolean isInstanceOf (String source, Throwable target) {
return target.getClass().getName().contains(source);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy