use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.
the class Waiter method waitForElementToBeDisplayed.
/**
* Method that waits for the Selenium isDisplayed() method to return true.
* Hence waits for an element to be displayed.
* Will wait for up to the specified amount of seconds.
*
* @param element - the WebElement to be displayed
* @param driver - the WebDriver instance
* @param specifiedTimeout - amount of seconds you want to wait for
*/
public void waitForElementToBeDisplayed(WebElement element, WebDriver driver, int specifiedTimeout) {
WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
ExpectedCondition<Boolean> elementIsDisplayed = arg0 -> element.isDisplayed();
wait.until(elementIsDisplayed);
}
use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.
the class Waiter method waitForElementAttributeEqualsString_IgnoreWhitespaces.
/**
* Method that waits for an element's attribute value (whose whitespaces are removed) to equal an expected
* String (whose whitespaces are also removed).
* Basically, does a getAttribute(nameOfAttribute) on the WebElement, removes all whitespaces from this resulting
* String, then compares this value to another String that contains no whitespaces.
* When calling the method, the expectedString can contain whitespaces, as they are removed inside this method.
* Whitespaces include: space, new line, tab.
* Having said that, only the non whitespace characters are compared.
* Therefore, 'this string here' will equal 'this string here'.
* Will wait for up to the specified timeout number of seconds for expected condition to occur.
*
* @param element - the WebElement whose attribute will be verified
* @param attribute - the attribute whose value will be verified
* @param expectedString - the expected value of the WebElement's attribute on which a whitespace removal is also
* done
* @param driver - the WebDriver instance
* @param specifiedTimeout - the amount of seconds to wait for the condition to occur
*/
public void waitForElementAttributeEqualsString_IgnoreWhitespaces(WebElement element, String attribute, String expectedString, WebDriver driver, int specifiedTimeout) {
WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
ExpectedCondition<Boolean> elementAttributeEqualsStringIW = arg0 -> element.getAttribute(attribute).replaceAll("\\s", "").equals(expectedString.replaceAll("\\s", ""));
wait.until(elementAttributeEqualsStringIW);
}
use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class DriverHelper method acceptAlert.
/**
* Accepts alert modal.
*/
public void acceptAlert() {
WebDriver drv = getDriver();
Wait<WebDriver> wait = new WebDriverWait(drv, EXPLICIT_TIMEOUT, RETRY_TIME);
try {
wait.until((Function<WebDriver, Object>) dr -> isAlertPresent());
drv.switchTo().alert().accept();
Messager.ALERT_ACCEPTED.info("");
} catch (Exception e) {
Messager.ALERT_NOT_ACCEPTED.error("");
}
}
use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class DriverHelper method isPageOpened.
public boolean isPageOpened(final AbstractPage page, long timeout) {
boolean result;
final WebDriver drv = getDriver();
Wait<WebDriver> wait = new WebDriverWait(drv, timeout, RETRY_TIME);
try {
wait.until((Function<WebDriver, Object>) dr -> LogicUtils.isURLEqual(page.getPageURL(), drv.getCurrentUrl()));
result = true;
} catch (Exception e) {
result = false;
}
if (!result) {
LOGGER.warn(String.format("Actual URL differs from expected one. Expected '%s' but found '%s'", page.getPageURL(), drv.getCurrentUrl()));
}
return result;
}
use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.
the class DriverHelper method cancelAlert.
/**
* Cancels alert modal.
*/
public void cancelAlert() {
WebDriver drv = getDriver();
Wait<WebDriver> wait = new WebDriverWait(drv, EXPLICIT_TIMEOUT, RETRY_TIME);
try {
wait.until((Function<WebDriver, Object>) dr -> isAlertPresent());
drv.switchTo().alert().dismiss();
Messager.ALERT_CANCELED.info("");
} catch (Exception e) {
Messager.ALERT_NOT_CANCELED.error("");
}
}
Aggregations