Example usage for org.openqa.selenium Proxy setAutodetect

List of usage examples for org.openqa.selenium Proxy setAutodetect

Introduction

In this page you can find the example usage for org.openqa.selenium Proxy setAutodetect.

Prototype

public Proxy setAutodetect(boolean autodetect) 

Source Link

Document

Specifies whether to autodetect proxy settings.

Usage

From source file:org.paxml.selenium.webdriver.NewSessionTag.java

License:Open Source License

private WebDriver createWebDriver(Context context) {
    Proxy proxy = new Proxy();
    if (StringUtils.isNotBlank(proxyHttp)) {
        proxy.setHttpProxy(proxyHttp);/*from   www .ja  va  2  s. com*/
    }
    if (StringUtils.isNotBlank(proxyFtp)) {
        proxy.setFtpProxy(proxyFtp);
    }
    if (StringUtils.isNotBlank(proxySsl)) {
        proxy.setSslProxy(proxySsl);
    }
    if (StringUtils.isNotBlank(proxyAutoConfigUrl)) {
        proxy.setProxyAutoconfigUrl(proxyAutoConfigUrl);
    }
    if (proxyAutoDetect != null) {
        proxy.setAutodetect(proxyAutoDetect);
    }

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.PROXY, proxy);
    cap.setJavascriptEnabled(true);

    if (StringUtils.isNotBlank(hub)) {
        final URL url;
        try {
            url = new URL(hub);
        } catch (MalformedURLException e) {
            throw new RuntimeException("hub url is invalid: " + hub, e);
        }
        if ("firefox".equalsIgnoreCase(browser)) {
            cap = cap.firefox();
        } else if ("iexplore".equalsIgnoreCase(browser)) {
            cap = cap.internetExplorer();
        } else if ("chrome".equalsIgnoreCase(browser)) {
            cap = cap.chrome();
        }
        return new RemoteWebDriver(url, cap);
    }

    if ("firefox".equalsIgnoreCase(browser)) {
        return new FirefoxDriver(cap);
    }
    if ("iexplore".equalsIgnoreCase(browser)) {
        return new InternetExplorerDriver(cap);
    }
    if ("chrome".equalsIgnoreCase(browser)) {
        return new ChromeDriver(cap);
    }

    throw new RuntimeException("unknown browser type: " + browser);

}