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:fll.web.WebWindow.java

License:Open Source License

private void checkForClosed() {
    if (handle == null || handle.equals(""))
        throw new WebDriverException("Web Window closed or not initialized handle: " + handle);
}

From source file:io.appium.java_client.android.HasNetworkConnection.java

License:Apache License

/**
 * Get the current network settings of the device.
 *
 * @return Connection object will let you inspect the status
 *     of None, AirplaneMode, Wifi, Data and All connections
 *///from   ww  w. j  av a 2s.  co  m
default Connection getConnection() {
    long bitMask = CommandExecutionHelper.execute(this, getNetworkConnectionCommand());
    Connection[] types = Connection.values();

    for (Connection connection : types) {
        if (connection.bitMask == bitMask) {
            return connection;
        }
    }
    throw new WebDriverException(
            "The unknown network connection " + "type has been returned. The bitmask is " + bitMask);
}

From source file:io.appium.java_client.AppiumFluentWait.java

License:Apache License

private <B> B getPrivateFieldValue(String fieldName, Class<B> fieldType) {
    try {//from w ww.j  av a 2  s .c  o  m
        final Field f = getClass().getSuperclass().getDeclaredField(fieldName);
        f.setAccessible(true);
        return fieldType.cast(f.get(this));
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new WebDriverException(e);
    }
}

From source file:io.appium.java_client.AppiumFluentWait.java

License:Apache License

private Object getPrivateFieldValue(String fieldName) {
    try {/*w w  w .j a  v a  2  s.  c o  m*/
        final Field f = getClass().getSuperclass().getDeclaredField(fieldName);
        f.setAccessible(true);
        return f.get(this);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new WebDriverException(e);
    }
}

From source file:io.appium.java_client.AppiumFluentWait.java

License:Apache License

/**
 * Repeatedly applies this instance's input value to the given function until one of the following
 * occurs:/*from  w  w w . j  a v a  2 s .  c  o  m*/
 * <ol>
 * <li>the function returns neither null nor false,</li>
 * <li>the function throws an unignored exception,</li>
 * <li>the timeout expires,</li>
 * <li>the current thread is interrupted</li>
 * </ol>.
 *
 * @param isTrue the parameter to pass to the expected condition
 * @param <V>    The function's expected return type.
 * @return The functions' return value if the function returned something different
 *         from null or false before the timeout expired.
 * @throws TimeoutException If the timeout expires.
 */
@Override
public <V> V until(Function<? super T, V> isTrue) {
    final Instant start = getClock().instant();
    final Instant end = getClock().instant().plus(getTimeout());
    long iterationNumber = 1;
    Throwable lastException;
    while (true) {
        try {
            V value = isTrue.apply(getInput());
            if (value != null && (Boolean.class != value.getClass() || Boolean.TRUE.equals(value))) {
                return value;
            }

            // Clear the last exception; if another retry or timeout exception would
            // be caused by a false or null value, the last exception is not the
            // cause of the timeout.
            lastException = null;
        } catch (Throwable e) {
            lastException = propagateIfNotIgnored(e);
        }

        // Check the timeout after evaluating the function to ensure conditions
        // with a zero timeout can succeed.
        if (end.isBefore(getClock().instant())) {
            String message = getMessageSupplier() != null ? getMessageSupplier().get() : null;

            String timeoutMessage = String.format(
                    "Expected condition failed: %s (tried for %d second(s) with %s interval)",
                    message == null ? "waiting for " + isTrue : message, getTimeout().getSeconds(),
                    getInterval());
            throw timeoutException(timeoutMessage, lastException);
        }

        try {
            Duration interval = getInterval();
            if (pollingStrategy != null) {
                final IterationInfo info = new IterationInfo(iterationNumber,
                        Duration.between(start, getClock().instant()), getTimeout(), interval);
                interval = pollingStrategy.apply(info);
            }
            getSleeper().sleep(interval);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new WebDriverException(e);
        }
        ++iterationNumber;
    }
}

From source file:io.appium.java_client.AppiumFluentWait.java

License:Apache License

protected Throwable propagateIfNotIgnored(Throwable e) {
    for (Class<? extends Throwable> ignoredException : getIgnoredExceptions()) {
        if (ignoredException.isInstance(e)) {
            return e;
        }/*from  w  w  w  .  j  a  v  a  2s . c o m*/
    }
    Throwables.throwIfUnchecked(e);
    throw new WebDriverException(e);
}

From source file:io.appium.java_client.remote.AppiumProtocolHandShake.java

License:Apache License

public Result createSession(HttpClient client, Command command) throws IOException, WebDriverException {

    Capabilities desired = ofNullable((Capabilities) command.getParameters().get("desiredCapabilities"))
            .orElseGet(DesiredCapabilities::new);

    Capabilities required = ofNullable((Capabilities) command.getParameters().get("requiredCapabilities"))
            .orElseGet(DesiredCapabilities::new);

    JsonParser parser = new JsonParser();
    JsonElement des = parser.parse(new BeanToJsonConverter().convert(desired));
    JsonElement req = parser.parse(new BeanToJsonConverter().convert(required));

    JsonObject jsonObject = new JsonObject();

    amendW3CParameters(jsonObject, des, req);
    amendOssParamters(jsonObject, des, req);
    Optional<Result> result = createSession(client, jsonObject);

    return ofNullable(result.orElseGet(() -> {
        JsonObject jsonObject1 = new JsonObject();
        amendOssParamters(jsonObject1, des, req);

        try {/*from w ww. ja  v a  2s  . c  om*/
            return createSession(client, jsonObject1).orElseGet(() -> {
                JsonObject jsonObject2 = new JsonObject();
                amendW3CParameters(jsonObject2, des, req);

                try {
                    return createSession(client, jsonObject2).orElse(null);
                } catch (IOException e) {
                    throw new WebDriverException(e);
                }
            });
        } catch (IOException e) {
            throw new WebDriverException(e);
        }
    })).orElseThrow(() -> new SessionNotCreatedException(String.format(
            "Unable to create new remote session. " + "desired capabilities = %s, required capabilities = %s",
            desired, required)));
}

From source file:io.appium.java_client.ws.StringWebSocketClient.java

License:Apache License

/**
 * This event if fired when there is an unexpected
 * error in web socket connection./*from   ww w . j  ava 2 s  .  co m*/
 *
 * @param cause the actual error reason
 */
@OnError
public void onError(Throwable cause) {
    this.session = null;
    getErrorHandlers().forEach(x -> x.accept(cause));
    throw new WebDriverException(cause);
}

From source file:io.appium.java_client.ws.WebSocketClient.java

License:Apache License

/**
 * Connects web socket client.//from  w w  w  .  j a  v  a2 s . c  o m
 *
 * @param endpoint The full address of an endpoint to connect to.
 *                 Usually starts with 'ws://'.
 */
public void connect(URI endpoint) {
    try {
        ContainerProvider.getWebSocketContainer().connectToServer(this, endpoint);
        setEndpoint(endpoint);
    } catch (IOException | DeploymentException e) {
        throw new WebDriverException(e);
    }
}

From source file:net.mindengine.galen.page.selenium.SeleniumPage.java

License:Apache License

private List<WebElement> driverFindElements(By by) {
    if (objectContext == null) {
        try {/*from  w  ww.  j a v a 2s  .  co  m*/
            return driver.findElements(by);
        } catch (NullPointerException e) {
            throw new WebDriverException(e);
        } catch (StaleElementReferenceException e) {
            throw new WebDriverException(e);
        }
    } else {
        return objectContext.findElements(by);
    }
}