Example usage for org.openqa.selenium WebDriverException getMessage

List of usage examples for org.openqa.selenium WebDriverException getMessage

Introduction

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

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:com.opera.core.systems.OperaDesktopDriverTest.java

License:Apache License

@Test
public void autostartDisabled() {
    OperaSettings settings = new OperaSettings();
    settings.autostart(false);//from   ww  w  . j a  v a2 s . co m

    try {
        new TestOperaDesktopDriver(settings);
        fail("Expected exception");
    } catch (WebDriverException e) {
        assertThat(e.getCause(), instanceOf(ResponseNotReceivedException.class));
        assertThat(e.getMessage(), containsString("No response in a timely fashion"));
    }
}

From source file:com.opera.core.systems.OperaDesktopDriverTest.java

License:Apache License

@Test
public void environmentalBinaryPathIsRespected() {
    environment.set(OperaBinary.OPERA_PATH_ENV_VAR, resources.executableBinary().getPath());

    try {/*from ww w .  j  av a  2s  .  c o m*/
        new TestOperaDesktopDriver();
        fail("Expected exception");
    } catch (WebDriverException e) {
        assertThat(e.getCause(), instanceOf(OperaRunnerException.class));
        assertThat(e.getMessage(), containsString("Could not start Opera"));
    }
}

From source file:com.opera.core.systems.OperaDriverTest.java

License:Apache License

@Test
public void testMultipleOperas() throws Exception {
    DesiredCapabilities capabilities = OperaDriverTestCase.getDefaultCapabilities();
    capabilities.setCapability(OperaDriver.PROFILE, (String) null); // random profile
    capabilities.setCapability(OperaDriver.PORT, 0); // random port

    OperaDriver a;//from  w  w  w.j  a  va 2s.co m
    OperaDriver b;
    OperaDriver c;
    try {
        a = new OperaDriver(capabilities);
        b = new OperaDriver(capabilities);
        c = new OperaDriver(capabilities);
    } catch (WebDriverException e) {
        // If immediately exited, then it doesn't support the flags
        if (e.getMessage().contains("Opera exited immediately")) {
            return;
        } else {
            throw e;
        }
    }

    a.get(fixture("test.html"));
    b.get(fixture("javascript.html"));
    c.get(fixture("keys.html"));

    assertTrue("Instance a has url test.html", a.getCurrentUrl().endsWith("test.html"));
    assertTrue("Instance a has url javascript.html", b.getCurrentUrl().endsWith("javascript.html"));
    assertTrue("Instance a has url keys.html", c.getCurrentUrl().endsWith("keys.html"));

    a.quit();
    b.quit();
    c.quit();
}

From source file:com.opera.core.systems.SessionTest.java

License:Apache License

@Test
public void multipleInstances() {
    TestDriver a;//from ww w .  ja v  a  2 s  . c  o m
    TestDriver b;
    TestDriver c;

    try {
        a = new TestDriverBuilder().get();
        b = new TestDriverBuilder().get();
        c = new TestDriverBuilder().get();
    } catch (WebDriverException e) {
        // If immediately exited, then it doesn't support the flags
        if (e.getMessage().contains("Opera exited immediately")) {
            return;
        } else {
            throw e;
        }
    }

    a.navigate().to(pages.test);
    b.navigate().to(pages.javascript);
    c.navigate().to(pages.keys);

    assertThat(a.getCurrentUrl(), containsString("test.html"));
    assertThat(b.getCurrentUrl(), containsString("javascript.html"));
    assertThat(c.getCurrentUrl(), containsString("keys.html"));

    a.quit();
    b.quit();
    c.quit();
}

From source file:com.partnet.automation.selenium.AbstractConfigurableDriverProvider.java

License:Apache License

/**
 * Helper method to launch remote web driver.
 *
 * At times there are issues with starting the remote web driver. For firefox,
 * problems with locking port 7054 can arise.
 *
 * See the Selenium <a/*from w  w  w  .j  a v  a  2  s  . c o m*/
 * href="https://code.google.com/p/selenium/issues/detail?id=4790">bug</a> for
 * more info
 *
 * A special case needs to be performed for the Android browser, since it can not be cast to {@link RemoteWebDriver}
 *
 * @param capabilities web driver capabilities.
 * @return {@link WebDriver} instance of the remote web driver
 *
 */
protected WebDriver initRemoteWebDriver(DesiredCapabilities capabilities) {
    URL remoteUrl = getRemoteSeleniumUrl();
    LOG.debug("Remote Selenium URL: {}", remoteUrl.toString());
    WebDriver driver = null;
    boolean isAndroid = false;
    int tries = 1;

    if (capabilities.getCapability(CapabilityType.BROWSER_NAME).equals(ANDROID_BROWSER_NAME)) {
        isAndroid = true;
    }

    while (driver == null) {
        LOG.debug("Try {} {}", tries, capabilities.toString());

        try {

            if (isAndroid) {
                driver = new AndroidDriver(remoteUrl, capabilities);
            } else {
                driver = new RemoteWebDriver(remoteUrl, capabilities);
            }

        } catch (WebDriverException e) {
            LOG.error("Remote WebDriver was unable to start! " + e.getMessage(), e);

            if (tries >= Integer.getInteger(REMOTE_WEBDRIVER_RETRY_ATTEMPTS, 10)) {
                throw e;
            }

            sleep(Integer.getInteger(REMOTE_WEBDRIVER_RETRY_PAUSE_MILLIS, 5000) * tries);
            tries++;
            driver = null;
        }
    }

    if (!isAndroid) {
        // allow screenshots to be taken
        driver = new Augmenter().augment(driver);
    }

    // Allow files from the host to be uploaded to a remote browser
    ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());

    return driver;
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * The function will search for the element and then click on it using
 * the Click method of java script./*from   ww  w  .  j  a  v a2s.  c  o m*/
 *
 * @param driver
 * @param locator
 */
public void ClickJS(WebDriver driver, By locator) {
    this.log.debug("ClickJS::Enter");
    this.log.debug("Locator: " + locator.toString());

    WebElement element = WaitForElementPresenceAndVisible(driver, locator);
    if (element != null) {
        try {
            JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("arguments[0].click();", element);
        } catch (WebDriverException wde) {
            if (wde.getMessage().contains("arguments[0].click is not a function")) {
                element.click();
            }
        }
    } else {
        this.log.error("Element is null " + locator.toString());
    }

    this.log.debug("ClickJS::Exit");
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * The function will search for the element present (doesn't matter
 * if element is visible or not) and then click on it.
 *
 * @param driver/*from   ww  w  . ja va 2  s . c om*/
 * @param locator
 */
public void ClickElementInvisible(WebDriver driver, By locator) {
    this.log.debug("ClickElementInvisible::Enter");
    this.log.debug("Locator: " + locator.toString());

    WebElement element = FindElementInvisible(driver, locator);
    if (element != null) {
        try {
            JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("arguments[0].click();", element);
        } catch (WebDriverException wde) {
            if (wde.getMessage().contains("arguments[0].click is not a function")) {
                element.click();
            }
        }
    } else {
        this.log.error("Element is null " + locator.toString());
    }

    this.log.debug("ClickElementInvisible::Exit");
}

From source file:com.qwazr.crawler.web.driver.BrowserDriver.java

License:Apache License

public Object executeScript(String javascript, boolean faultTolerant, Object... objects) {
    try {// www. ja v  a 2  s  .  c o m
        if (!(driver instanceof JavascriptExecutor))
            throw new WebDriverException("The Web driver does not support javascript execution");
        JavascriptExecutor js = (JavascriptExecutor) driver;
        return js.executeScript(javascript, objects);
    } catch (WebDriverException e) {
        if (!faultTolerant)
            throw e;
        logger.warn(e.getMessage(), e);
        return null;
    }
}

From source file:com.seleniumtests.browserfactory.AbstractWebDriverFactory.java

License:Apache License

public void cleanUp() {
    try {/*from   w  w w . java 2s .c  om*/
        if (driver != null) {
            try {
                TestLogging.log("quiting webdriver" + Thread.currentThread().getId());
                driver.quit();
            } catch (WebDriverException ex) {
                TestLogging.log("Exception encountered when quiting driver: "
                        + WebUIDriver.getWebUIDriver().getConfig().getBrowser().name() + ":" + ex.getMessage());
            }

            driver = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.seleniumtests.browserfactory.SeleniumGridDriverFactory.java

License:Apache License

/**
 * Connect to grid using RemoteWebDriver
 * As we may have several grid available, takes the first one where driver is created
 * @param url/*from  ww  w  .j  av  a 2 s . co m*/
 * @param capability
 * @return
 */
private WebDriver getDriver(MutableCapabilities capability) {
    driver = null;

    Clock clock = Clock.systemUTC();
    Instant end = clock.instant().plusSeconds(retryTimeout);
    Exception currentException = null;

    while (end.isAfter(clock.instant())) {

        for (SeleniumGridConnector gridConnector : gridConnectors) {

            // if grid is not active, wait 30 secs
            if (!gridConnector.isGridActive()) {
                logger.warn(String.format("grid %s is not active, looking for the next one",
                        gridConnector.getHubUrl().toString()));
                continue;
            }

            try {
                driver = new RemoteWebDriver(gridConnector.getHubUrl(), capability);
                activeGridConnector = gridConnector;
                break;
            } catch (WebDriverException e) {
                logger.warn(String.format("Error creating driver on hub %s: %s",
                        gridConnector.getHubUrl().toString(), e.getMessage()));
                currentException = e;
                continue;
            }
        }

        // do not wait more
        if (driver != null) {
            break;
        }

        if (currentException != null) {
            WaitHelper.waitForSeconds(5);
        } else {
            // we are here if no grid connector is available
            logger.warn("No grid available, wait 30 secs and retry");

            // for test only, reduce wiat
            if (retryTimeout > 1) {
                WaitHelper.waitForSeconds(30);
            } else {
                WaitHelper.waitForSeconds(1);
            }
        }
    }

    if (driver == null) {
        throw new SeleniumGridException("Cannot create driver on grid, it may be fully used", currentException);
    }

    return driver;
}