Example usage for org.openqa.selenium TimeoutException TimeoutException

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

Introduction

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

Prototype

public TimeoutException(Throwable cause) 

Source Link

Usage

From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww w. j  a v  a  2s .  co m*/
 */
@Override
public boolean isElementPresent(By locator, long wait) {

    try {
        getWait(wait).until(ExpectedConditions.presenceOfElementLocated(locator));
        return true;
    } catch (TimeoutException e) {
        logger.error("Timeout after waiting for presence of element by:  " + locator.toString());
        throw new TimeoutException(e.getMessage());
    }
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java

License:Apache License

/**
 * {@inheritDoc}/*from w  ww .  j a va  2s . com*/
 */
@Override
public boolean isElementVisible(By locator, boolean visibility, long wait) {

    if (visibility)
        try {
            getWait(wait).until(ExpectedConditions.visibilityOfElementLocated(locator));
            return true;
        } catch (TimeoutException e) {
            logger.error(
                    "Timeout after waiting " + wait + " for visibility of element by:  " + locator.toString());
            return false;
        }
    else
        try {
            getWait(wait).until(ExpectedConditions.invisibilityOfElementLocated(locator));
            return true;
        } catch (TimeoutException e) {
            logger.error("Timeout after waiting " + wait + " for invisibility of element by:  "
                    + locator.toString());
            throw new TimeoutException(e.getMessage());
        }

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java

License:Apache License

/**
 * {@inheritDoc}//from ww  w . ja v  a  2 s .  c o  m
 */
@Override
public boolean isElementClickable(By locator, long wait) {

    try {
        getWait(wait).until(ExpectedConditions.elementToBeClickable(locator));
        return true;
    } catch (TimeoutException e) {
        logger.error("Timeout after waiting for element to be clickable located by:  " + locator.toString());
        throw new TimeoutException(e.getMessage());
    }

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  w w . j  a  v  a  2s.c om*/
 */
@Override
public boolean isTextPresentInElementValue(By locator, String text, long wait) {
    try {
        getWait(wait).until(ExpectedConditions.textToBePresentInElementValue(locator, text));
        return true;
    } catch (TimeoutException e) {
        logger.error("Timeout after waiting text  " + text + " to be present in element located by "
                + locator.toString());
        throw new TimeoutException(e.getMessage());
    }
}

From source file:com.github.licanhua.test.framework.util.PageHelper.java

License:Apache License

public static void waitForDocumentReadyState(WebDriverContext webDriverContext) {
    logger.info("Wait for document.readyState is complete");
    Wait<WebDriver> wait = new WebDriverWait(webDriverContext.getWebDriver(),
            webDriverContext.getWaitDurationInSeconds(), 100);
    wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            try {
                return ((JavascriptExecutor) driver).executeScript("return document.readyState")
                        .equals("complete");
            } catch (TimeoutException e) {
                throw new TimeoutException("Load document timeout\n" + e.getMessage());
            }//from w w w. j  a  va2  s  . c  o m
        }
    });

}

From source file:com.machinepublishers.jbrowserdriver.AppThread.java

License:Apache License

static <T> T exec(final boolean pauseAfterExec, final StatusCode statusCode, final long timeout,
        final Sync<T> action) {
    try {//from ww  w  . j a v a  2  s .  c om
        if ((boolean) Platform.isFxApplicationThread()) {
            return action.perform();
        }
        final Runner<T> runner = new Runner<T>(action, statusCode);
        synchronized (runner.done) {
            Platform.runLater(runner);
        }
        synchronized (runner.done) {
            if (!runner.done.get()) {
                try {
                    runner.done.wait(timeout);
                } catch (InterruptedException e) {
                    LogsServer.instance().exception(e);
                }
                if (!runner.done.get()) {
                    runner.cancel.set(true);
                    throw new TimeoutException(new StringBuilder().append("Timeout of ").append(timeout)
                            .append("ms reached.").toString());
                }
            }
            handleExecutionException(runner.failure.get());
            return runner.returned.get();
        }
    } finally {
        if (pauseAfterExec) {
            pause();
        }
    }
}

From source file:com.machinepublishers.jbrowserdriver.ElementServer.java

License:Apache License

/**
 * {@inheritDoc}/*w  w  w  .j  ava  2s .  c o  m*/
 */
@Override
public Object executeAsyncScript(final String script, final Object... args) {
    final JavascriptNames jsNames = new JavascriptNames();
    script(true, script, args, jsNames);
    long timeoutAt = contextItem.context.get().timeouts.get().getScriptTimeoutMS();
    if (timeoutAt > 0) {
        timeoutAt += System.currentTimeMillis();
    } else {
        timeoutAt = Long.MAX_VALUE;
    }
    int sleep = 1;
    final int sleepBackoff = 2;
    final int sleepMax = 0x101;
    try {
        while (true) {
            sleep = sleep < sleepMax ? sleep * sleepBackoff : sleep;
            try {
                Thread.sleep(sleep);
            } catch (InterruptedException e) {
            }
            Object result = AppThread.exec(contextItem.statusCode, new Sync<Object>() {
                @Override
                public Object perform() {
                    validate(false);
                    return node.eval(new StringBuilder().append("(function(){return this.")
                            .append(jsNames.callbackVal).append(";})();").toString());
                }
            });
            if (!(result instanceof String) || !"undefined".equals(result.toString())) {
                Object parsed = parseScriptResult(result);
                if (parsed instanceof List) {
                    if (((List) parsed).size() == 0) {
                        return null;
                    }
                    if (((List) parsed).size() == 1) {
                        return ((List) parsed).get(0);
                    }
                }
                return parsed;
            }
            if (System.currentTimeMillis() > timeoutAt) {
                throw new TimeoutException(
                        "Timeout of " + contextItem.context.get().timeouts.get().getScriptTimeoutMS()
                                + "ms reached for waiting async script to complete.");
            }
        }
    } finally {
        AppThread.exec(contextItem.statusCode, new Sync<Object>() {
            @Override
            public Object perform() {
                validate(false);
                node.eval(new StringBuilder().append("delete ").append(jsNames.callbackVal).append(";")
                        .toString());
                return null;
            }
        });
    }
}

From source file:com.machinepublishers.jbrowserdriver.JBrowserDriverServer.java

License:Apache License

/**
 * {@inheritDoc}//from w  w  w . j  a va 2 s. c  o m
 */
@Override
public void get(final String url) {
    init();
    long start = System.currentTimeMillis();
    try {
        AppThread.exec(context.get().item().statusCode, context.get().timeouts.get().getPageLoadTimeoutMS(),
                new Sync<Object>() {
                    public Object perform() {
                        context.get().item().httpListener.get().resetStatusCode();
                        context.get().item().engine.get().load(url);
                        return null;
                    }
                });
        long end = System.currentTimeMillis();
        if (context.get().timeouts.get().getPageLoadTimeoutMS() == 0) {
            getStatusCode();
        } else {
            long waitMS = context.get().timeouts.get().getPageLoadTimeoutMS() - (end - start);
            if (waitMS > 0) {
                getStatusCode(waitMS);
            }
        }
    } finally {
        if (context.get().item().statusCode.get() == 0) {
            AppThread.exec(new Sync<Object>() {
                @Override
                public Object perform() {
                    context.get().item().engine.get().getLoadWorker().cancel();
                    throw new TimeoutException(new StringBuilder().append("Timeout of ")
                            .append(context.get().timeouts.get().getPageLoadTimeoutMS()).append("ms reached.")
                            .toString());
                }
            }, context.get().timeouts.get().getPageLoadTimeoutMS());
        }
    }
}

From source file:com.opera.core.systems.environment.webserver.WebbitAppServer.java

License:Apache License

private void waitFor(Future<? extends WebServer> server) {
    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() - startTime < 10000) {
        if (server.isCancelled()) {
            throw new TimeoutException("Timed out waiting for server to start");
        }/* w  w  w. j ava2 s .  co m*/
        if (server.isDone()) {
            return;
        }
    }
    throw new TimeoutException("Timed out waiting for server to start");
}

From source file:com.opera.core.systems.internal.CallbackWait.java

License:Apache License

private Exception propagateIfNotIgnored(Exception e) {
    for (Class<? extends RuntimeException> ignoredException : ignoredExceptions) {
        if (ignoredException.isInstance(e)) {
            return e;
        }//from   ww  w  .j a  va 2s  .  c o  m
    }

    throw new TimeoutException(e);
}