Example usage for org.openqa.selenium WebDriver manage

List of usage examples for org.openqa.selenium WebDriver manage

Introduction

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

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:com.technophobia.webdriver.substeps.runner.DefaultWebDriverFactory.java

License:Open Source License

public WebDriver createWebDriver() {

    final WebDriver webDriver;

    switch (configuration.driverType()) {
    case FIREFOX: {
        final DesiredCapabilities firefoxCapabilities = DesiredCapabilities.firefox();

        setNetworkCapabilities(firefoxCapabilities);

        setLoggingPreferences(firefoxCapabilities);

        webDriver = new FirefoxDriver(firefoxCapabilities);
        break;/*  ww w  .j a  v a2s . co  m*/

    }
    case HTMLUNIT: {
        final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_38);
        htmlUnitDriver.setJavascriptEnabled(!configuration.isJavascriptDisabledWithHTMLUnit());

        // Run via a proxy - firstly try deprecated HTML unit only
        // properties
        final String htmlunitProxyHost = configuration.getHtmlUnitProxyHost();
        if (StringUtils.isNotEmpty(htmlunitProxyHost)) {
            final int htmlunitProxyPort = configuration.getHtmlUnitProxyPort();
            htmlUnitDriver.setProxy(htmlunitProxyHost, htmlunitProxyPort);
        }
        // Run via a proxy - secondly new network proxy settings
        final String proxyHost = configuration.getNetworkProxyHost();
        if (StringUtils.isNotEmpty(proxyHost)) {
            final int proxyPort = configuration.getNetworkProxyPort();
            htmlUnitDriver.setProxy(proxyHost, proxyPort);
        }

        setDriverLocale(htmlUnitDriver);

        webDriver = htmlUnitDriver;
        break;

    }
    case CHROME: {

        String preset = System.getProperty("webdriver.chrome.driver");

        if (preset == null) {
            String driverPath = configuration.getChromeDriverPath();
            Assert.assertNotNull(
                    "Chromedriver path not set as a -Dwebdriver.chrome.driver parameter or in config",
                    driverPath);
            System.setProperty("webdriver.chrome.driver", driverPath);
        }

        final DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
        setNetworkCapabilities(chromeCapabilities);

        setLoggingPreferences(chromeCapabilities);

        webDriver = new ChromeDriver(chromeCapabilities);
        break;

    }
    case IE: {

        // apparently this is required to get around some IE security
        // restriction.
        final DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);

        LOG.warn("Using IE Webdriver with IGNORING SECURITY DOMAIN");

        setNetworkCapabilities(ieCapabilities);
        webDriver = new InternetExplorerDriver(ieCapabilities);
        break;
    }
    default: {
        throw new IllegalArgumentException("unknown driver type " + configuration.driverType());
    }
    }

    webDriver.manage().window().maximize();

    return webDriver;

}

From source file:com.technophobia.webdriver.substeps.runner.DefaultWebDriverFactory.java

License:Open Source License

public void shutdownWebDriver(WebDriverContext webDriverContext) {
    LOG.debug("Shutting WebDriver down");
    WebDriver webDriver = webDriverContext.getWebDriver();
    if (webDriver != null) {
        webDriver.manage().deleteAllCookies();
        webDriver.quit();//from w  ww  . j  a  v a2  s  .c  om
    }

}

From source file:com.technophobia.webdriver.substeps.runner.DefaultWebDriverFactory.java

License:Open Source License

public boolean resetWebDriver(WebDriverContext webDriverContext) {
    LOG.debug("Resetting WebDriver");
    WebDriver webDriver = webDriverContext.getWebDriver();
    if (webDriver != null) {
        webDriver.manage().deleteAllCookies();
    }/*from w  w  w  .jav  a  2 s  .  c om*/

    return true;
}

From source file:com.thoughtworks.go.framework.Steps.java

License:Apache License

public Steps(WebDriver driver) {
    this.driver = driver;
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    this.cache = new HashMap<>();
}

From source file:com.thoughtworks.inproctester.tests.InProcessHtmlUnitDriverTest.java

License:Apache License

@Test
public void shouldSupportCookies() {
    WebDriver htmlUnitDriver = new InProcessHtmlUnitDriver(httpAppTester);
    htmlUnitDriver.manage().deleteAllCookies();

    htmlUnitDriver.get("http://localhost/contacts/add");
    htmlUnitDriver.findElement(By.name("contactName")).sendKeys("My Contact");
    htmlUnitDriver.findElement(By.tagName("form")).submit();

    assertThat(htmlUnitDriver.findElement(By.className("message")).getText(), is("Success"));

    htmlUnitDriver.get("http://localhost/contacts/1");

    Cookie flashMessageCookie = htmlUnitDriver.manage().getCookieNamed("FLASH_MESSAGE");
    assertThat(flashMessageCookie, is(nullValue()));

    assertThat(htmlUnitDriver.findElements(By.className("message")), is(Matchers.<WebElement>empty()));
}

From source file:com.thoughtworks.selenium.SeleneseTestNgHelperVir.java

License:Apache License

/**
 * Start of test case.//from w ww.ja v a 2 s.  c o  m
 */
public final void startOfTestCase() {
    WebDriver driver = getDriver();
    final int pageloadTimeOut = 300;
    try {
        driver.manage().window().maximize();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
    try {
        driver.manage().timeouts().pageLoadTimeout(pageloadTimeOut, TimeUnit.SECONDS);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.thoughtworks.selenium.webdriven.commands.CreateCookie.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String nameValuePair, String optionsString) {
    Matcher nameValuePairMatcher = NAME_VALUE_PAIR_PATTERN.matcher(nameValuePair);
    if (!nameValuePairMatcher.find())
        throw new SeleniumException("Invalid parameter: " + nameValuePair);

    String name = nameValuePairMatcher.group(1);
    String value = nameValuePairMatcher.group(2);

    Matcher maxAgeMatcher = MAX_AGE_PATTERN.matcher(optionsString);
    Date maxAge = null;/*from  w  w  w  .  j a va 2 s.  co  m*/

    if (maxAgeMatcher.find()) {
        maxAge = new Date(System.currentTimeMillis() + Integer.parseInt(maxAgeMatcher.group(1)) * 1000);
    }

    String path = null;
    Matcher pathMatcher = PATH_PATTERN.matcher(optionsString);
    if (pathMatcher.find()) {
        path = pathMatcher.group(1);
        try {
            if (path.startsWith("http")) {
                path = new URL(path).getPath();
            }
        } catch (MalformedURLException e) {
            // Fine.
        }
    }

    Cookie cookie = new Cookie(name, value, path, maxAge);
    driver.manage().addCookie(cookie);

    return null;
}

From source file:com.thoughtworks.selenium.webdriven.commands.DeleteAllVisibleCookies.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    driver.manage().deleteAllCookies();
    return null;//from  w w  w.j av a  2  s  . c  om
}

From source file:com.thoughtworks.selenium.webdriven.commands.DeleteCookie.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String name, String ignored) {
    Cookie cookie = driver.manage().getCookieNamed(name);

    if (cookie != null) {
        driver.manage().deleteCookieNamed(name);
    }/*from   w  w  w.  ja v a2s .com*/

    return null;
}

From source file:com.thoughtworks.selenium.webdriven.commands.GetCookie.java

License:Apache License

@Override
protected String handleSeleneseCommand(WebDriver driver, String ignored, String alsoIgnored) {
    StringBuilder builder = new StringBuilder();
    for (Cookie c : driver.manage().getCookies()) {
        builder.append(c.toString());/* ww w  .ja v a2  s . c om*/
        builder.append("; ");
    }
    return builder.toString();
}