Java Code Examples for org.openqa.selenium.WebDriverException#getCause()

The following examples show how to use org.openqa.selenium.WebDriverException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScreenshotUtils.java    From Selenium-Foundation with Apache License 2.0 6 votes vote down vote up
/**
 * Produce a screenshot from the specified driver.
 * 
 * @param optDriver optional web driver object
 * @param reason impetus for capture request; may be 'null'
 * @param logger SLF4J logger object; may be 'null'
 * @return screenshot artifact; if capture fails, an empty byte array is returned
 */
public static byte[] getArtifact(
                final Optional<WebDriver> optDriver, final Throwable reason, final Logger logger) { //NOSONAR
    
    if (canGetArtifact(optDriver, logger)) {
        try {
            WebDriver driver = optDriver.get();
            return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
        } catch (WebDriverException e) {
            if (e.getCause() instanceof ClassCastException) {
                return proxyArtifact();
            } else if (logger != null) {
                logger.warn("The driver is capable of taking a screenshot, but it failed.", e);
            }
        }
    }
    return new byte[0];
}
 
Example 2
Source File: QAFExtendedWebDriver.java    From qaf with MIT License 5 votes vote down vote up
public <T> T extractScreenShot(WebDriverException e, OutputType<T> target) {
	if (e.getCause() instanceof ScreenshotException) {
		String base64Str = ((ScreenshotException) e.getCause()).getBase64EncodedScreenshot();
		return target.convertFromBase64Png(base64Str);
	}
	return null;
}
 
Example 3
Source File: QAFWebDriverCommandProcessor.java    From qaf with MIT License 5 votes vote down vote up
public String extractScreenShot(WebDriverException e) {
	Throwable cause = e.getCause();
	if (cause instanceof ScreenshotException) {
		return ((ScreenshotException) cause).getBase64EncodedScreenshot();
	}
	return null;
}
 
Example 4
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether exception indicates connection with webdriver is lost.
 * @param e exception caught
 * @return true if exception indicated we can no longer communicate with webdriver.
 */
public boolean exceptionIndicatesConnectionLost(WebDriverException e) {
    boolean result = e.getCause() instanceof SocketException;
    if (!result && e.getMessage() != null) {
        result = e.getMessage().contains("java.net.SocketException")
                || e.getMessage().contains("java.net.ConnectException");
    }
    return result;
}
 
Example 5
Source File: XpiDriverService.java    From selenium with Apache License 2.0 5 votes vote down vote up
/**
 * Configures and returns a new {@link XpiDriverService} using the default configuration. In
 * this configuration, the service will use the firefox executable identified by the
 * {@link FirefoxDriver.SystemProperty#BROWSER_BINARY} system property on a free port.
 *
 * @return A new XpiDriverService using the default configuration.
 */
public static XpiDriverService createDefaultService() {
  try {
    return new Builder().build();
  } catch (WebDriverException e) {
    throw new IllegalStateException(e.getMessage(), e.getCause());
  }
}
 
Example 6
Source File: JettyAppServer.java    From selenium with Apache License 2.0 5 votes vote down vote up
private void addJsResourceHandler(String handlerPath, String dirPath) {
  Path path;
  try {
    path = locate(dirPath);
  } catch (WebDriverException e) {
    // Ugly hack to get us started with bazel while sorting out missing data dependencies.
    if (Boolean.getBoolean(getClass().getPackage().getName() + ".ignoreMissingJsRoots")
        && e.getCause() instanceof FileNotFoundException) {
      System.err.println("WARNING: failed to add resource handler " + handlerPath + ": " + e.getCause());
      return;
    }
    throw e;
  }
  addResourceHandler(handlerPath, path);
}