public class PollingWait extends Object
private PollingWait wait = new PollingWait().timeoutAfter(5, SECONDS) .pollEvery(100, MILLISECONDS); @Test public void test_auto_complete() throws Exception { // Enter "cheese" into auto complete field ... ... wait.Since version 2.0 you can also use a lambda expression or a method reference instead of auntil
(newRunnableAssert
("'cheesecake' is displayed in auto-complete <div>") { @Override public void run() throws Exception { WebElement autoCompleteDiv = driver.findElement(By.id("auto-complete")); assertThat(autoCompleteDiv, isVisible()); assertThat(autoCompleteDiv, containsText("cheesecake")); } }); }
RunnableAssert
like this:
private PollingWait wait = new PollingWait().timeoutAfter(5, SECONDS) .pollEvery(100, MILLISECONDS); @Test public void test_login() throws Exception { // Enter credentials into login form ... clickOnButton("Login"); wait.until
(() -> webDriver.findElement(By.linkText("Logout")).isDisplayed()); ... } protected void clickOnButton(String label) { WebElement button = findButton(label); wait.until
(button::isDisplayed); button.click(); }
Constructor and Description |
---|
PollingWait() |
Modifier and Type | Method and Description |
---|---|
PollingWait |
pollEvery(long timeAmount,
TimeUnit timeUnit)
Default: 50 milliseconds.
|
PollingWait |
timeoutAfter(long timeAmount,
TimeUnit timeUnit)
Default: 30 seconds.
|
void |
until(Callable<Boolean> shouldBeTrue)
Repetitively executes the given
Callable<Boolean>
until it returns true or until the configured
timeout is reached, in which case an
AssertionError will be thrown. |
void |
until(RunnableAssert runnableAssert)
Repetitively executes the given
runnableAssert
until it succeeds without throwing an Error or
Exception or until the configured timeout
is reached, in which case an AssertionError will be thrown. |
public PollingWait timeoutAfter(long timeAmount, @Nonnull TimeUnit timeUnit)
public PollingWait pollEvery(long timeAmount, @Nonnull TimeUnit timeUnit)
public void until(@Nonnull RunnableAssert runnableAssert)
runnableAssert
until it succeeds without throwing an Error
or
Exception
or until the configured timeout
is reached, in which case an AssertionError
will be thrown.
Calls Thread.sleep(long)
before each retry using the configured
interval
to free the CPU for other threads/processes.public void until(@Nonnull Callable<Boolean> shouldBeTrue)
Callable<Boolean>
until it returns true
or until the configured
timeout
is reached, in which case an
AssertionError
will be thrown. Calls Thread.sleep(long)
before each retry using the configured interval
to free the CPU for other threads/processes.Copyright © 2017. All rights reserved.