Search in sources :

Example 11 with Wait

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);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 12 with Wait

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);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 13 with Wait

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("");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) HttpURLConnection(java.net.HttpURLConnection) SpecialKeywords(com.qaprosoft.carina.core.foundation.commons.SpecialKeywords) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) WebElement(org.openqa.selenium.WebElement) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Matcher(java.util.regex.Matcher) AbstractPage(com.qaprosoft.carina.core.gui.AbstractPage) Duration(java.time.Duration) Actions(org.openqa.selenium.interactions.Actions) Parameter(com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) java.util.concurrent(java.util.concurrent) MethodHandles(java.lang.invoke.MethodHandles) List(java.util.List) TimeoutException(org.openqa.selenium.TimeoutException) CryptoTool(com.qaprosoft.carina.core.foundation.crypto.CryptoTool) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) Pattern(java.util.regex.Pattern) DriverListener(com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) java.util(java.util) Wait(org.openqa.selenium.support.ui.Wait) DataFlavor(java.awt.datatransfer.DataFlavor) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) Configuration(com.qaprosoft.carina.core.foundation.utils.Configuration) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) Action(org.openqa.selenium.interactions.Action) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CommonUtils(com.qaprosoft.carina.core.foundation.utils.common.CommonUtils) Assert(org.testng.Assert) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) LogicUtils(com.qaprosoft.carina.core.foundation.utils.LogicUtils) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) Messager(com.qaprosoft.carina.core.foundation.utils.Messager) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) IOException(java.io.IOException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) InputStreamReader(java.io.InputStreamReader) java.awt(java.awt) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FluentWait(org.openqa.selenium.support.ui.FluentWait) Cookie(org.openqa.selenium.Cookie) BufferedReader(java.io.BufferedReader) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException)

Example 14 with Wait

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) HttpURLConnection(java.net.HttpURLConnection) SpecialKeywords(com.qaprosoft.carina.core.foundation.commons.SpecialKeywords) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) WebElement(org.openqa.selenium.WebElement) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Matcher(java.util.regex.Matcher) AbstractPage(com.qaprosoft.carina.core.gui.AbstractPage) Duration(java.time.Duration) Actions(org.openqa.selenium.interactions.Actions) Parameter(com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) java.util.concurrent(java.util.concurrent) MethodHandles(java.lang.invoke.MethodHandles) List(java.util.List) TimeoutException(org.openqa.selenium.TimeoutException) CryptoTool(com.qaprosoft.carina.core.foundation.crypto.CryptoTool) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) Pattern(java.util.regex.Pattern) DriverListener(com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) java.util(java.util) Wait(org.openqa.selenium.support.ui.Wait) DataFlavor(java.awt.datatransfer.DataFlavor) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) Configuration(com.qaprosoft.carina.core.foundation.utils.Configuration) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) Action(org.openqa.selenium.interactions.Action) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CommonUtils(com.qaprosoft.carina.core.foundation.utils.common.CommonUtils) Assert(org.testng.Assert) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) LogicUtils(com.qaprosoft.carina.core.foundation.utils.LogicUtils) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) Messager(com.qaprosoft.carina.core.foundation.utils.Messager) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) IOException(java.io.IOException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) InputStreamReader(java.io.InputStreamReader) java.awt(java.awt) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FluentWait(org.openqa.selenium.support.ui.FluentWait) Cookie(org.openqa.selenium.Cookie) BufferedReader(java.io.BufferedReader) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException)

Example 15 with Wait

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("");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) HttpURLConnection(java.net.HttpURLConnection) SpecialKeywords(com.qaprosoft.carina.core.foundation.commons.SpecialKeywords) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) WebElement(org.openqa.selenium.WebElement) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Matcher(java.util.regex.Matcher) AbstractPage(com.qaprosoft.carina.core.gui.AbstractPage) Duration(java.time.Duration) Actions(org.openqa.selenium.interactions.Actions) Parameter(com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) java.util.concurrent(java.util.concurrent) MethodHandles(java.lang.invoke.MethodHandles) List(java.util.List) TimeoutException(org.openqa.selenium.TimeoutException) CryptoTool(com.qaprosoft.carina.core.foundation.crypto.CryptoTool) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) Pattern(java.util.regex.Pattern) DriverListener(com.qaprosoft.carina.core.foundation.webdriver.listener.DriverListener) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) java.util(java.util) Wait(org.openqa.selenium.support.ui.Wait) DataFlavor(java.awt.datatransfer.DataFlavor) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) Configuration(com.qaprosoft.carina.core.foundation.utils.Configuration) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) Action(org.openqa.selenium.interactions.Action) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CommonUtils(com.qaprosoft.carina.core.foundation.utils.common.CommonUtils) Assert(org.testng.Assert) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) LogicUtils(com.qaprosoft.carina.core.foundation.utils.LogicUtils) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) Messager(com.qaprosoft.carina.core.foundation.utils.Messager) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) IOException(java.io.IOException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) InputStreamReader(java.io.InputStreamReader) java.awt(java.awt) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FluentWait(org.openqa.selenium.support.ui.FluentWait) Cookie(org.openqa.selenium.Cookie) BufferedReader(java.io.BufferedReader) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException)

Aggregations

Wait (org.openqa.selenium.support.ui.Wait)29 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)27 WebDriver (org.openqa.selenium.WebDriver)23 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)22 WebElement (org.openqa.selenium.WebElement)22 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)22 Function (java.util.function.Function)9 TimeoutException (org.openqa.selenium.TimeoutException)7 SpecialKeywords (com.qaprosoft.carina.core.foundation.commons.SpecialKeywords)6 CryptoTool (com.qaprosoft.carina.core.foundation.crypto.CryptoTool)6 Configuration (com.qaprosoft.carina.core.foundation.utils.Configuration)6 Parameter (com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter)6 LogicUtils (com.qaprosoft.carina.core.foundation.utils.LogicUtils)6 Messager (com.qaprosoft.carina.core.foundation.utils.Messager)6 CommonUtils (com.qaprosoft.carina.core.foundation.utils.common.CommonUtils)6 ExtendedWebElement (com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)6 AbstractPage (com.qaprosoft.carina.core.gui.AbstractPage)6 List (java.util.List)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6