Explanation about how to change the default timeout using explicitly wait in Selenium WebDriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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