List of usage examples for org.openqa.selenium TimeoutException TimeoutException
public TimeoutException(String message, Throwable cause)
From source file:com.github.licanhua.test.framework.util.PageHelper.java
License:Apache License
private static <T> void waitForElement(String message, ElementContext context, final T element, final Predicate<T> predicate) { WebDriver webDriver = context.getWebDriver(); int waitDuration = context.getWaitDurationInSeconds(); try {//from w ww. jav a 2 s . c o m Wait<WebDriver> wait = new WebDriverWait(webDriver, waitDuration, 100); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(final WebDriver webDriver) { try { return predicate.apply(element); } catch (final NoSuchElementException e) { return false; } catch (final StaleElementReferenceException e) { return false; } } }); } catch (TimeoutException e) { TimeoutException te = new TimeoutException(message + " timeout!", e); throw te; } }
From source file:com.jhyhh.appium.AndroidDriverWait.java
License:Apache License
@Override protected RuntimeException timeoutException(String message, Throwable lastException) { TimeoutException ex = new TimeoutException(message, lastException); ex.addInfo(WebDriverException.DRIVER_INFO, driver.getClass().getName()); if (driver instanceof RemoteWebDriver) { RemoteWebDriver remote = (RemoteWebDriver) driver; if (remote.getSessionId() != null) { ex.addInfo(WebDriverException.SESSION_ID, remote.getSessionId().toString()); }//from w ww . j av a 2 s.c o m if (remote.getCapabilities() != null) { ex.addInfo("Capabilities", remote.getCapabilities().toString()); } } throw ex; }
From source file:com.opera.core.systems.internal.CallbackWait.java
License:Apache License
/** * Throws a timeout exception. This method may be overridden to throw an exception that is * idiomatic for a particular test infrastructure, such as an AssertionError in JUnit4. * * @param message the timeout message * @param lastException the last exception to be thrown and subsequently suppressed while waiting * on a function//ww w. j ava 2 s .c o m * @return nothing will ever be returned; this return type is only specified as a convenience */ protected RuntimeException timeoutException(String message, Exception lastException) { throw new TimeoutException(message, lastException); }
From source file:org.alfresco.po.share.SharePopup.java
License:Open Source License
/** * Clicks on the No button for no upgrade document for google docs. * * @return HtmlPage//from ww w. java 2s . c o m */ public HtmlPage cancelNo() { try { WebElement prompt = findAndWait(PROMPT_PANEL_ID); List<WebElement> elements = prompt.findElements(BUTTON_TAG_NAME); WebElement cancelButton = findButton("No", elements); cancelButton.click(); } catch (TimeoutException nse) { throw new TimeoutException("upgrade prompt was not found", nse); } waitForPageLoad(SECONDS.convert(maxPageLoadingTime, MILLISECONDS)); return getCurrentPage(); }
From source file:org.alfresco.po.share.SharePopup.java
License:Open Source License
/** * Clicks on the submit button to allow upgrade document for google docs. * *///from w w w .j ava2 s. co m public void clickYes() { try { WebElement prompt = findAndWait(PROMPT_PANEL_ID); List<WebElement> elements = prompt.findElements(BUTTON_TAG_NAME); WebElement okButton = findButton("Yes", elements); okButton.click(); } catch (TimeoutException te) { throw new TimeoutException("upgrade prompt was not found", te); } catch (NoSuchElementException te) { throw new PageOperationException("authorisation prompt was not found", te); } }
From source file:org.alfresco.po.share.site.document.CopyOrMoveContentPage.java
License:Open Source License
/** * This method finds and clicks on Create Link button * /*from w ww . j av a2 s . c o m*/ * @return HtmlPage */ public HtmlPage selectCreateLinkButton() { try { WebElement button = driver.findElement(copyCreateLinkButtonCss); button.click(); waitUntilAlert(); return getCurrentPage(); } catch (NoSuchElementException | StaleElementReferenceException nse) { logger.error("Create Link button not visible. ", nse); throw new NoSuchElementException("Create Link button not visible. ", nse); } catch (TimeoutException te) { logger.error("Unable to find Create Link element. ", te); throw new TimeoutException("Unable to find Create Link element. ", te); } }
From source file:org.auraframework.test.util.WebDriverWaitWithCallback.java
License:Apache License
public <V2, V1> V1 until(Function<? super WebDriver, V1> function, Function<? super WebDriver, V2> callbackWhenTimeout) { try {/*from ww w.ja va 2s . co m*/ return super.until(function); } catch (TimeoutException e) { // catch timeout exception and throw exception with extra message from callback function V2 ret = callbackWhenTimeout.apply(driver); throw new TimeoutException(e.getMessage() + "\n" + ret.toString(), e.getCause()); } }
From source file:org.jboss.hal.testsuite.finder.FinderNavigation.java
License:Open Source License
private WebElement[] navigate(Boolean exactRowText) { WebElement[] columnRow = new WebElement[2]; if (refresh) { // Console.withBrowser(browser).refreshAndNavigate(page); Console.withBrowser(browser).withPageLoadTimeout(pageLoadTimeout).waitForFirstNavigationPanel(page); }/*from ww w . j av a2 s. c om*/ for (int i = 0; i < address.size(); i++) { AddressTuple tuple = address.get(i); columnRow[0] = browser.findElement(columnSelector(tuple.column)); if (!WILDCARD.equals(tuple.row)) { By rowSelector = exactRowText ? rowSelectorEquals(tuple.row) : rowSelector(tuple.row); columnRow[1] = new Find().elementWithGuiTimeout(columnRow[0], rowSelector); if (!columnRow[1].isDisplayed()) { ((JavascriptExecutor) browser).executeScript("arguments[0].scrollIntoView(true);", columnRow[1]); } columnRow[1].click(); hook.performAfterRowClick(); Graphene.waitModel().until().element(columnRow[0], rowSelector).attribute("class") .contains("cellTableSelectedRowCell"); // wait for next column to be visible if (i < address.size() - 1) { AddressTuple nextTuple = address.get(i + 1); try { Graphene.waitModel().until().element(columnSelector(nextTuple.column)).is().visible(); // TODO remove catch as soon as JBEAP-2168 is fixed! } catch (TimeoutException e) { if (ConfigUtils.get("jbeap2168workaround") != null && naviRetriesNo++ < 3) { log.warn("Navigation frozen! JBEAP-2168 needs to be fixed!"); return navigate(exactRowText); } else { naviRetriesNo = 0; throw new TimeoutException( "Navigation frozen! Probably due to JBEAP-2168 or changed navigation tree.", e); } } } } } naviRetriesNo = 0; return columnRow; }
From source file:org.jboss.test.selenium.support.ui.WebDriverWait.java
License:Open Source License
public <V> V until(Function<? super WebDriver, V> isTrue) { if (message == null) { return super.until(isTrue); } else {/*from w w w.j av a 2s .c o m*/ try { return super.until(isTrue); } catch (TimeoutException e) { throw new TimeoutException(message, e); } } }
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>/*from ww w . ja v a 2 s. co m*/ * <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); } } }