use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.
the class Waiter method waitForElementTextContainsString_IgnoreCase.
/**
* Method that then waits for the text on the element to contain an
* expected String but ignoring the case of the two.
* Checks whether the value resulted from getText() on the element contains the expected String, but without taking
* into account the case of the two values.
* Therefore, for example 'tHis' will contain 'his'.
* Will wait for up to the specifiedTimeout number of seconds for the text on the element to be the expected one.
*
* @param element - the WebElement whose text will be checked
* @param expectedString - the value expected to be part of the WebElement's text, ignoring the case
* @param driver - the WebDriver instance
* @param specifiedTimeout - amount of seconds you want to wait for
*/
public void waitForElementTextContainsString_IgnoreCase(WebElement element, String expectedString, WebDriver driver, int specifiedTimeout) {
WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
ExpectedCondition<Boolean> elementTextContainsString = arg0 -> element.getText().toLowerCase().contains(expectedString.toLowerCase());
wait.until(elementTextContainsString);
}
use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.
the class Waiter method waitForElementAttributeContainsString.
/**
* Method that waits for an element's specified attribute's value to contain another specified String.
* Compares the value resulted from getAttribute(nameOfAttribute) on the element with the expected String.
* Will wait for up to the specified number of seconds for the condition to occur.
*
* @param element - the WebElement whose attribute we are interested in
* @param attribute - the attribute whose value needs to be compared to another value
* @param expectedString - the expected value of the WebElement's attribute
* @param driver - the WebDriver instance
* @param specifiedTimeout - amount of seconds you want to wait for
*/
public void waitForElementAttributeContainsString(WebElement element, String attribute, String expectedString, WebDriver driver, int specifiedTimeout) {
WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
ExpectedCondition<Boolean> elementAttributeContainsString = arg0 -> element.getAttribute(attribute).contains(expectedString);
wait.until(elementAttributeContainsString);
}
use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.
the class Waiter method waitForUrl_IgnoreCase.
/**
* Wait for an expected URL to load in the browser, but ignore the case of the url.
* Compares a lower case value of the actual url in the browser with the lower case value of the expected url.
* Wait for the specifiedTimeout number of seconds.
*
* @param url - the url expected to load in the browser, ignoring its case
* @param driver - the WebDriver instance
* @param specifiedTimeout - amount of seconds you want to wait for
*/
public void waitForUrl_IgnoreCase(String url, WebDriver driver, int specifiedTimeout) {
WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
ExpectedCondition<Boolean> urlIsCorrect = arg0 -> driver.getCurrentUrl().toLowerCase().equals(url.toLowerCase());
wait.until(urlIsCorrect);
waitForPageLoadComplete(driver, specifiedTimeout);
}
use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class DriverHelper method getCurrentUrl.
/**
* Get a string representing the current URL that the browser is looking at.
* @param timeout
* @return validation result.
*/
public String getCurrentUrl(long timeout) {
WebDriver drv = getDriver();
// explicitly limit time for the getCurrentUrl operation
Future<?> future = Executors.newSingleThreadExecutor().submit(new Callable<String>() {
public String call() throws Exception {
// organize fluent waiter for getting url
Wait<WebDriver> wait = new FluentWait<WebDriver>(drv).pollingEvery(Duration.ofMillis(Configuration.getInt(Parameter.RETRY_INTERVAL))).withTimeout(Duration.ofSeconds(Configuration.getInt(Parameter.EXPLICIT_TIMEOUT))).ignoring(WebDriverException.class).ignoring(// org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters rea
JsonException.class);
return wait.until(new Function<WebDriver, String>() {
public String apply(WebDriver driver) {
return drv.getCurrentUrl();
}
});
}
});
String url = "";
try {
url = (String) future.get(timeout, TimeUnit.SECONDS);
} catch (java.util.concurrent.TimeoutException e) {
LOGGER.debug("Unable to get driver url during " + timeout + "sec!", e);
} catch (InterruptedException e) {
LOGGER.debug("Unable to get driver url during " + timeout + "sec!", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
LOGGER.error("ExecutionException error on get driver url!", e);
} catch (Exception e) {
LOGGER.error("Undefined error on get driver url detected!", e);
}
return url;
}
Aggregations