Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Last active August 10, 2020 17:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Explanation about how to change the default timeout using explicitly wait in Selenium WebDriver
public class ExplicitlyWaitExampleTest {
private WebDriver driver;
private WebDriverWait wait;
@BeforeClass
public void preCondition() {
driver = new ChromeDriver();
}
@BeforeMethod
public void beforeEachTest() {
wait = new WebDriverWait(driver, Duration.ofSeconds(5));
}
@Test
public void usingRegularTimeout1() {
WebElement menu = driver.findElement(By.id("buger"));
wait.until(ExpectedConditions.visibilityOf(menu));
}
@Test
public void usingRegularTimeout2() {
By cpf = By.name("cpf_document");
wait.until(ExpectedConditions.presenceOfElementLocated(cpf));
}
@Test
public void overridingDefaultTimeout() {
By uploadSuccessfull = By.cssSelector(".sucess.upload");
// overriding the default timeout only for this wait
wait.
withTimeout(Duration.ofSeconds(30)).
withMessage("timeout while waiting for upload to finish").
until(ExpectedConditions.presenceOfElementLocated(uploadSuccessfull));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment