org.openqa.selenium.TimeoutException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中org.openqa.selenium.TimeoutException.<init>()方法的一些代码示例,展示了TimeoutException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeoutException.<init>()方法的具体详情如下:
包路径:org.openqa.selenium.TimeoutException
类名称:TimeoutException
方法名:<init>

TimeoutException.<init>介绍

暂无

代码示例

代码示例来源:origin: com.github.seykron/htmlunit-maven-plugin

/** {@inheritDoc}
 */
public void timeoutError(final HtmlPage htmlPage, final long allowedTime,
  final long executionTime) {
 exception = new TimeoutException("JavaScript timeout. Allowed time: "
   + allowedTime + ", Execution time: " + executionTime);
}

代码示例来源:origin: com.opera/operadriver

/**
 * 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
 * @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);
}

代码示例来源:origin: net.serenity-bdd/core

protected RuntimeException timeoutException(String message, RuntimeException lastException) {
  throw new TimeoutException(message, lastException);
}

代码示例来源:origin: net.thucydides/thucydides-core

protected RuntimeException timeoutException(String message, RuntimeException lastException) {
  throw new TimeoutException(message, lastException);
}

代码示例来源:origin: net.serenity-bdd/serenity-core

protected RuntimeException timeoutException(String message, RuntimeException lastException) {
  throw new TimeoutException(message, lastException);
}

代码示例来源:origin: com.opera/operadriver

private Exception propagateIfNotIgnored(Exception e) {
 for (Class<? extends RuntimeException> ignoredException : ignoredExceptions) {
  if (ignoredException.isInstance(e)) {
   return e;
  }
 }
 throw new TimeoutException(e);
}

代码示例来源:origin: com.pojosontheweb/selenium-utils-core

/**
 * Evaluates this ListFindr. Throws
 * a TimeoutException if the condition chain didn't match.
 * @param failureMessage A message to include in the timeout exception
 * @throws TimeoutException if at least one condition in the chain failed
 */
public void eval(String failureMessage) throws TimeoutException {
  try {
    eval(IDENTITY_LIST);
  } catch(TimeoutException e) {
    throw new TimeoutException(failureMessage, e);
  }
}

代码示例来源:origin: com.pojosontheweb/selenium-utils-core

/**
 * Evaluates this Findr, and blocks until all conditions are satisfied. Throws
 * a TimeoutException otherwise.
 * @param failureMessage A message to be included to the timeout exception
 */
public void eval(String failureMessage) throws TimeoutException {
  try {
    eval();
  } catch(TimeoutException e) {
    throw new TimeoutException(failureMessage, e);
  }
}

代码示例来源:origin: com.pojosontheweb/selenium-utils-core

/**
 * Evaluates this ListFindr and invokes passed callback if the whole chain suceeded. Throws
 * a TimeoutException with passed failure message if the condition chain didn't match.
 * @param callback the callback to call if the chain succeeds
 * @param <T> the rturn type of the callback
 * @return the result of the callback
 * @throws TimeoutException if at least one condition in the chain failed
 */
public <T> T eval(Function<List<WebElement>, T> callback, String failureMessage) throws TimeoutException {
  try {
    return eval(callback);
  } catch(TimeoutException e) {
    throw new TimeoutException(failureMessage, e);
  }
}

代码示例来源:origin: com.pojosontheweb/selenium-utils-core

/**
 * Evaluates this Findr, and invokes passed callback if the whole chain succeeds. Throws
 * a TimeoutException with passed failure message otherwise.
 * @param callback the callback to invoke (called if the whole chain of conditions succeeded)
 * @param <T> the return type of the callback
 * @param failureMessage A message to be included to the timeout exception
 * @return the result of the callback
 * @throws TimeoutException if at least one condition in the chain failed
 */
public <T> T eval(final Function<WebElement,T> callback, String failureMessage) throws TimeoutException {
  try {
    return eval(callback);
  } catch (TimeoutException e) {
    throw new TimeoutException(failureMessage, e);
  }
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver

/**
 * Waits for the script to signal it is done by calling {@link #callback(Object) callback}.
 *
 * @return The script result.
 * @throws InterruptedException If this thread is interrupted before a result is ready.
 */
Object waitForResult() throws InterruptedException {
 long startTimeNanos = System.nanoTime();
 latch.await();
 if (isTimeout) {
  long elapsedTimeNanos = System.nanoTime() - startTimeNanos;
  long elapsedTimeMillis = TimeUnit.NANOSECONDS.toMillis(elapsedTimeNanos);
  throw new TimeoutException(
    "Timed out waiting for async script result after " + elapsedTimeMillis + "ms");
 }
 if (unloadDetected) {
  throw new WebDriverException(
    "Detected a page unload event; executeAsyncScript does not work across page loads");
 }
 return value;
}

代码示例来源:origin: com.pojosontheweb/selenium-utils-core

private <T> T wrapWebDriverWait(final Function<WebDriver,T> callback) throws TimeoutException {
  try {
    return new WebDriverWait(driver, waitTimeout, sleepInMillis).until(callback);
  } catch(TimeoutException e) {
    // failed to find element(s), build exception message
    // and re-throw exception
    StringBuilder sb = new StringBuilder();
    for (Iterator<String> it = path.iterator(); it.hasNext(); ) {
      sb.append(it.next());
      if (it.hasNext()) {
        sb.append("->");
      }
    }
    throw new TimeoutException("Timed out trying to find path=" + sb.toString() + ", callback=" + callback, e);
  }
}

代码示例来源:origin: jenkinsci/acceptance-test-harness

private void waitForOnLineSlave(final Slave s, int timeout){
  logger.info(String.format("Wait for the new slave %s to come online in %s seconds",machine.getId(), timeout));
  try {
    long endTime = System.currentTimeMillis()+ TimeUnit.SECONDS.toMillis(timeout);
    while (System.currentTimeMillis()<endTime) {
      if(s.isOnline()){
        slaveWaitComplete.set(true);
        return;
      }
      elasticSleep(1000);
    }
    throw new org.openqa.selenium.TimeoutException(String.format("Slave could not be online in %s seconds",timeout));
  } catch (RuntimeException e) {
    throw e;
  } catch (Exception e) {
    throw new Error(String.format("An exception occurred while waiting for slave to be online in %s seconds",timeout),e);
  }
}

代码示例来源:origin: com.pojosontheweb/selenium-utils-core

private <T> T wrapWebDriverWaitList(final Function<WebDriver,T> callback) throws TimeoutException {
  try {
    return new WebDriverWait(driver, waitTimeout, sleepInMillis).until(callback);
  } catch(TimeoutException e) {
    // failed to find element(s), build exception message
    // and re-throw exception
    ArrayList<String> newPath = new ArrayList<String>(path);
    newPath.add(by.toString());
    StringBuilder sb = new StringBuilder();
    for (Iterator<String> it = newPath.iterator(); it.hasNext(); ) {
      sb.append(it.next());
      if (it.hasNext()) {
        sb.append("->");
      }
    }
    throw new TimeoutException("Timed out trying to find path=" + sb.toString() + ", callback=" + callback, e);
  }
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui

/**
 * Wait till the livetable has finished displaying all its rows (so that we can then assert the livetable content
 * without running the risk that the rows have not been updated yet).
 */
public void waitUntilReady()
{
  long t1 = System.currentTimeMillis();
  while ((System.currentTimeMillis() - t1 < getDriver().getTimeout() * 1000L)) {
    if (isReady()) {
      return;
    }
    try {
      Thread.sleep(50);
    } catch (InterruptedException e) {
      // Do nothing just break out
      break;
    }
  }
  throw new TimeoutException("Livetable isn't ready after the timeout has expired.");
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver

@Override
 public void refresh() {
  if (lastPage() instanceof HtmlPage) {
   try {
    ((HtmlPage) lastPage()).refresh();
   } catch (SocketTimeoutException e) {
    throw new TimeoutException(e);
   } catch (IOException e) {
    throw new WebDriverException(e);
   }
  }
 }
}

代码示例来源:origin: org.kurento/kurento-room-test

public void waitWhileElement(String label, Browser browser, String id) throws TimeoutException {
 int originalTimeout = 60;
 try {
  originalTimeout = browser.getTimeout();
  log.debug("Original browser timeout (s): {}, set to 1", originalTimeout);
  browser.setTimeout(1);
  browser.changeTimeout(1);
  new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY)
    .until(ExpectedConditions.invisibilityOfElementLocated(By.id(id)));
 } catch (org.openqa.selenium.TimeoutException e) {
  log.warn("Timeout when waiting for element {} to disappear in browser {}", id, label, e);
  throw new TimeoutException("Element with id='" + id + "' is present in page after "
    + testTimeout + " seconds");
 } finally {
  browser.setTimeout(originalTimeout);
  browser.changeTimeout(originalTimeout);
 }
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-administration-test-pageobjects

/**
 * Select the specified color theme.
 * @param colorThemeName name of the color theme to select
 */
public void setColorTheme(String colorThemeName)
{
  // Make sure the color theme that we want to set is available from the list first
  try {
    getDriver().waitUntilCondition(driver -> getColorThemeOptionElement(colorThemeName) != null);
  } catch (TimeoutException e) {
    // Collect all available options to display a nice message
    List<String> options = new ArrayList<>();
    for (WebElement option : getColorThemeOptions()) {
      options.add(option.getText());
    }
    throw new TimeoutException(String.format("Color theme [%s] wasn't found among [%s]", colorThemeName,
      StringUtils.join(options, ',')), e);
  }
  // Click on it to set the theme
  getColorThemeOptionElement(colorThemeName).click();
  // Waiting to be sure the change is effective
  getDriver().waitUntilCondition(driver -> StringUtils.equals(getCurrentColorTheme(), colorThemeName));
}

代码示例来源:origin: cz.etnetera/seb

@Override
protected RuntimeException timeoutException(String message, Throwable lastException) {
  TimeoutException ex = new TimeoutException(message, lastException);
  ex.addInfo(WebDriverException.DRIVER_INFO, context.getDriver().getClass().getName());
  if (context.getDriver() instanceof RemoteWebDriver) {
    RemoteWebDriver remote = (RemoteWebDriver) context.getDriver();
    if (remote.getSessionId() != null) {
      ex.addInfo(WebDriverException.SESSION_ID, remote.getSessionId().toString());
    }
    if (remote.getCapabilities() != null) {
      ex.addInfo("Capabilities", remote.getCapabilities().toString());
    }
  }
  throw ex;
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver

/**
 * Allows HtmlUnit's about:blank to be loaded in the constructor, and may be useful for other
 * tests?
 *
 * @param fullUrl The URL to visit
 */
protected void get(URL fullUrl) {
 try {
  getWebClient().getPage(fullUrl);
  // A "get" works over the entire page
  currentWindow = getCurrentWindow().getTopWindow();
 } catch (UnknownHostException e) {
  getCurrentWindow().getTopWindow().setEnclosedPage(new UnexpectedPage(
    new StringWebResponse("Unknown host", fullUrl),
    getCurrentWindow().getTopWindow()
  ));
 } catch (ConnectException e) {
  // This might be expected
 } catch (SocketTimeoutException e) {
  throw new TimeoutException(e);
 } catch (Exception e) {
  throw new WebDriverException(e);
 }
 gotPage = true;
 pickWindow();
 resetKeyboardAndMouseState();
}

相关文章