Reputation: 47
Somewhere I read that mixing Implicit and Explicit gives unprecitable result. Is it true?
Source: https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#advanceduserinteractions
WARNING: Do not mix implicit and explicit waits! Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.
In that case, do we need to give less time/equal to Implicit wait???
Upvotes: 0
Views: 50
Reputation: 3635
Honestly, with a good implementation of test automation framework, you don't need implicitWait
. You should always explicitly wait for the conditions.
The implicit wait might cause your tests to run slower. Automated Test Suite should always run as fast as possible to provide feedback to the team.
BUT, if you insist on using it, you can simply create some kind of method/class where you turn off implicit waits, perform explicit wait, and restore implicit wait value.
Something like this:
public class Wait {
private static final int IMPLICIT_WAIT_TIME = 10; //store your default implicit wait here or use .properties file
private WebDriver driver;
private int timeout = 10;
private List<Class<? extends Throwable>> exceptions = new ArrayList<>();
public Wait(WebDriver driver) {
this.driver = driver;
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //turn off implicit wait
}
public Wait setTimeout(int seconds) {
this.timeout = seconds;
return this;
}
@SafeVarargs
public final Wait ignoring(Class<? extends Throwable>... exceptions) {
this.exceptions.addAll(Arrays.asList(exceptions));
return this;
}
public void until(ExpectedCondition... expectedConditions) {
WebDriverWait wait = new WebDriverWait(driver, timeout);
if (exceptions.size() > 0) {
wait.ignoreAll(exceptions);
}
wait.until(ExpectedConditions.and(expectedConditions));
driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME, TimeUnit.SECONDS); //restore implicit wait
}
}
Upvotes: 3