Search in sources :

Example 26 with Wait

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);
}
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 27 with Wait

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);
}
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 28 with Wait

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);
}
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 29 with Wait

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) JsonException(org.openqa.selenium.json.JsonException) java.util.concurrent(java.util.concurrent) 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) Function(java.util.function.Function) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Wait(org.openqa.selenium.support.ui.Wait) FluentWait(org.openqa.selenium.support.ui.FluentWait)

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