use of io.appium.java_client.AppiumFluentWait in project java-client by appium.
the class AppiumFluentWaitTest method testIntervalCalculationForCustomStrategy.
@Test
public void testIntervalCalculationForCustomStrategy() {
final FakeElement el = new FakeElement();
final AtomicInteger callsCounter = new AtomicInteger(0);
// Linear dependency
final Function<Long, Long> pollingStrategy = x -> x * 2;
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, new SystemClock(), duration -> {
int callNumber = callsCounter.incrementAndGet();
assertThat(duration.in(TimeUnit.SECONDS), is(equalTo(pollingStrategy.apply((long) callNumber))));
Thread.sleep(duration.in(TimeUnit.MILLISECONDS));
}).withPollingStrategy(info -> new Duration(pollingStrategy.apply(info.getNumber()), TimeUnit.SECONDS)).withTimeout(4, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS);
try {
wait.until(FakeElement::isDisplayed);
Assert.fail("TimeoutException is expected");
} catch (TimeoutException e) {
// this is expected
assertThat(callsCounter.get(), is(equalTo(2)));
}
}
use of io.appium.java_client.AppiumFluentWait in project java-client by appium.
the class AppiumFluentWaitTest method testCustomStrategyOverridesDefaultInterval.
@Test
public void testCustomStrategyOverridesDefaultInterval() {
final FakeElement el = new FakeElement();
final AtomicInteger callsCounter = new AtomicInteger(0);
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, new SystemClock(), duration -> {
callsCounter.incrementAndGet();
assertThat(duration.in(TimeUnit.SECONDS), is(equalTo(2L)));
Thread.sleep(duration.in(TimeUnit.MILLISECONDS));
}).withPollingStrategy(info -> new Duration(2, TimeUnit.SECONDS)).withTimeout(3, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS);
try {
wait.until(FakeElement::isDisplayed);
Assert.fail("TimeoutException is expected");
} catch (TimeoutException e) {
// this is expected
assertThat(callsCounter.get(), is(equalTo(2)));
}
}
Aggregations