use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class AbstractUIObjectListHandler method waitUntil.
/**
* Wait until any condition happens.
*
* @param condition - ExpectedCondition.
* @return true if condition happen.
*/
@SuppressWarnings("unchecked")
private boolean waitUntil(ExpectedCondition<?> condition) {
boolean result;
long timeout = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);
long RETRY_TIME = Configuration.getLong(Parameter.RETRY_INTERVAL);
@SuppressWarnings("rawtypes") Wait wait = new WebDriverWait(webDriver, timeout, RETRY_TIME).ignoring(WebDriverException.class).ignoring(NoSuchSessionException.class);
try {
wait.until(condition);
result = true;
LOGGER.debug("waitUntil: finished true...");
} catch (NoSuchElementException | TimeoutException e) {
// don't write exception even in debug mode
LOGGER.debug("waitUntil: NoSuchElementException | TimeoutException e..." + condition.toString());
result = false;
} catch (Exception e) {
LOGGER.error("waitUntil: " + condition.toString(), e);
result = false;
}
return result;
}
use of org.openqa.selenium.support.ui.Wait 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 org.openqa.selenium.support.ui.Wait 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)));
}
}
use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class DriverHelper method isElementPresent.
@Deprecated
public boolean isElementPresent(String elementName, final By by, long timeout) {
boolean result;
final WebDriver drv = getDriver();
wait = new WebDriverWait(drv, timeout, RETRY_TIME);
try {
setImplicitTimeout(0);
wait.until((Function<WebDriver, Object>) dr -> !dr.findElements(by).isEmpty() && dr.findElement(by).isDisplayed());
result = true;
} catch (Exception e) {
result = false;
} finally {
setImplicitTimeout(IMPLICIT_TIMEOUT);
}
return result;
}
use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class DriverHelper method isTitleAsExpected.
/**
* Checks that page title is as expected.
*
* @param expectedTitle
* Expected title
* @return validation result.
*/
public boolean isTitleAsExpected(final String expectedTitle) {
boolean result;
final String decryptedExpectedTitle = cryptoTool.decryptByPattern(expectedTitle, CRYPTO_PATTERN);
final WebDriver drv = getDriver();
wait = new WebDriverWait(drv, EXPLICIT_TIMEOUT, RETRY_TIME);
try {
wait.until((Function<WebDriver, Object>) dr -> drv.getTitle().contains(decryptedExpectedTitle));
result = true;
Messager.TITLE_CORERECT.info(drv.getCurrentUrl(), expectedTitle);
} catch (Exception e) {
result = false;
Messager.TITLE_NOT_CORERECT.error(drv.getCurrentUrl(), expectedTitle, drv.getTitle());
}
return result;
}
Aggregations