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