Created
August 20, 2020 20:27
-
-
Save eliasnogueira/0034a9535298211b79b92bc2a5a9824d to your computer and use it in GitHub Desktop.
Example about how to override the Explicitly Wait using 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() { | |
WebDriverManager.chromedriver().setup(); | |
driver = new ChromeDriver(); | |
driver.get("https://codepen.io/eliasnogueira/full/MWywxVr"); | |
driver.switchTo().frame("result"); | |
} | |
@BeforeMethod | |
public void beforeEachTest() { | |
wait = new WebDriverWait(driver, Duration.ofSeconds(5)); | |
} | |
@Test | |
public void thisTestWillPass() { | |
driver.findElement(By.id("trigger_4")).click(); | |
By elementVisibleAfter4Seconds = By.id("after_4"); | |
wait.until(ExpectedConditions.visibilityOfElementLocated(elementVisibleAfter4Seconds)); | |
} | |
@Test(priority = 2) | |
public void thisTestWillPassBecauseOfTheTimeoutOverride() { | |
driver.findElement(By.id("trigger_13")).click(); | |
By elementVisibleAfter13Seconds = By.id("after_13"); | |
// overriding the default timeout only for this wait | |
wait. | |
withTimeout(Duration.ofSeconds(15)). | |
withMessage("timeout while waiting for upload to finish"). | |
until(ExpectedConditions.visibilityOfElementLocated(elementVisibleAfter13Seconds)); | |
} | |
@Test(priority = 3) | |
public void thisTestWillFail() { | |
driver.findElement(By.id("trigger_6")).click(); | |
By elementVisibleAfter6Seconds = By.id("after_6"); | |
wait.until(ExpectedConditions.visibilityOfElementLocated(elementVisibleAfter6Seconds)); | |
} | |
@AfterClass | |
public void postCondition() { | |
driver.quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment