Example usage for org.openqa.selenium WebDriverException WebDriverException

List of usage examples for org.openqa.selenium WebDriverException WebDriverException

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriverException WebDriverException.

Prototype

public WebDriverException(Throwable cause) 

Source Link

Usage

From source file:ru.stqa.selenium.wait.ActionRepeater.java

License:Apache License

/**
 * Repeatedly attempts to perform the action until one of the following occurs:
 * <ol>// w  w w . j  a  v a  2s  .  c om
 * <li>the function returns a value that should not be ignored,</li>
 * <li>the function throws a exception that should not be ignored,</li>
 * <li>the timeout expires,
 * <li>
 * <li>the current thread is interrupted</li>
 * </ol>
 *
 * @param action the action to be performed repeatedly
 * @param <V> The action's expected return type.
 * @return The action' return value if the action returned a result that should not be ignored.
 * @throws org.openqa.selenium.TimeoutException If the timeout expires.
 */
public <V> V tryTo(RepeatableAction<? super T, V> action) {
    long end = clock.laterBy(timeout.in(MILLISECONDS));
    Throwable lastException = null;
    while (true) {
        try {
            V result = action.apply(context);
            if (!action.shouldIgnoreResult(result)) {
                return result;
            }
        } catch (Throwable e) {
            if (!action.shouldIgnoreException(e)) {
                throw Throwables.propagate(e);
            } else {
                lastException = e;
            }
        }

        // Check the timeout after evaluating the function to ensure conditions
        // with a zero timeout can succeed.
        if (!clock.isNowBefore(end)) {
            String toAppend = message == null ? " trying to perform action " + action.toString()
                    : ": " + message;

            String timeoutMessage = String.format("Timed out after %d seconds%s", timeout.in(SECONDS),
                    toAppend);
            throw new TimeoutException(timeoutMessage, lastException);
        }

        try {
            sleeper.sleep(interval);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new WebDriverException(e);
        }
    }
}

From source file:ru.stqa.selenium.wrapper.WebDriverWrapper.java

License:Apache License

@Override
public Object executeScript(String script, Object... args) {
    WebDriver driver = getWrappedDriver();
    if (driver instanceof JavascriptExecutor) {
        return wrapObject(((JavascriptExecutor) driver).executeScript(script, args));
    } else {/*from   w w  w .java  2s.c o m*/
        throw new WebDriverException("Wrapped webdriver does not support JavascriptExecutor: " + driver);
    }
}

From source file:ru.stqa.selenium.wrapper.WebDriverWrapper.java

License:Apache License

@Override
public Object executeAsyncScript(String script, Object... args) {
    WebDriver driver = getWrappedDriver();
    if (driver instanceof JavascriptExecutor) {
        return wrapObject(((JavascriptExecutor) driver).executeAsyncScript(script, args));
    } else {// w w w .ja va  2s.c  om
        throw new WebDriverException("Wrapped webdriver does not support JavascriptExecutor: " + driver);
    }
}

From source file:sandeep.kb.android.remote.android.AndroidWebDriver.java

License:Apache License

void waitForPageToLoad() {
    sleepQuietly(200);//from  w  ww . java2s . c  o  m
    pageDoneLoading = false;
    pageStartedLoading = true;
    long endTime = System.currentTimeMillis() + loadingTimeOut;
    while (System.currentTimeMillis() < endTime) {
        String pageLoadState = executeJavascriptInWebView("document.readyState");
        if ("complete".equals(pageLoadState)) {
            resetPageIsLoading();
            return;
        } else {
            continue;
        }
    }
    throw new WebDriverException("Web Page failed to load after waiting for " + loadingTimeOut
            + " millis. Please increase the timeout in WebDriver manager.");

}

From source file:sandeep.kb.android.remote.android.AndroidWebDriver.java

License:Apache License

public static void sleepQuietly(long ms) {
    try {//from  w w  w  .j a  va  2  s  . co m
        Thread.sleep(ms);
    } catch (InterruptedException cause) {
        Thread.currentThread().interrupt();
        throw new WebDriverException(cause);
    }
}

From source file:sandeep.kb.android.remote.android.AndroidWebDriver.java

License:Apache License

private void throwIfError(final JSONObject jsonObject) {
    int status;/*from  w ww.ja v a  2 s  .  c  o  m*/
    String errorMsg;
    try {
        status = (Integer) jsonObject.get(STATUS);
        errorMsg = String.valueOf(jsonObject.get(VALUE));
    } catch (JSONException e) {
        throw new RuntimeException("Failed to parse JSON Object: " + jsonObject, e);
    }
    switch (status) {
    case ErrorCodes.SUCCESS:
        return;
    case ErrorCodes.NO_SUCH_ELEMENT:
        throw new NoSuchElementException("Could not find " + "WebElement.");
    case ErrorCodes.STALE_ELEMENT_REFERENCE:
        throw new StaleElementReferenceException("WebElement is stale.");
    default:
        if (jsonObject.toString()
                .contains("Result of expression 'd.evaluate' [undefined] is" + " not a function.")) {
            throw new WebDriverException("You are using a version of Android WebDriver APK"
                    + " compatible with ICS SDKs or more recent SDKs. For more info take a look at"
                    + " http://code.google.com/p/selenium/wiki/AndroidDriver#Supported_Platforms. Error:" + " "
                    + jsonObject.toString());
        }
        throw new WebDriverException("Error: " + errorMsg);
    }
}

From source file:sandeep.kb.android.remote.driver.AndroidRemoteWebDriver.java

public AndroidRemoteWebDriver() {
    super();/*from   w  ww .  ja v  a2 s . co m*/

    String deviceID = System.getProperty("deviceID");
    String wsUrl = System.getProperty("wsUrl");

    Utils.log("AndroidWebDriver", "DeviceId = " + deviceID);
    setDeviceId(deviceID);

    Utils.log("AndroidWebDriver", "Url = " + wsUrl);
    if (wsUrl != null && !wsUrl.equals("null")) {
        this.setWsUrl(wsUrl);
    } else {
        Utils.log("AndroidRemoteWebDriver", "WsUrl is null");
        throw new WebDriverException("Web socket url not specified");
    }

}