Java 类org.openqa.selenium.Proxy.ProxyType 实例源码

项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates a phantomJs webdriver.
 *
 * @return
 *         A phantomJs webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generatePhantomJsDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.PHANTOMJS);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating Phantomjs driver ({}) ...", pathWebdriver);

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "fr-FR");
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathWebdriver);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    String proxy = "";
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        proxy = Context.getProxy().getHttpProxy();
    }
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
            new String[] { "--proxy=" + proxy, "--web-security=no", "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--webdriver-loglevel=NONE" });
    return new PhantomJSDriver(capabilities);
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates a htmlunit webdriver.
 *
 * @return
 *         A htmlunit webdriver
 */
private WebDriver generateHtmlUnitDriver() {
    logger.info("Generating HtmlUnit driver...");
    final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }
    return new HtmlUnitDriver(capabilities);
}
项目:frameworkium-core    文件:AbstractDriver.java   
/**
 * Get proxy object with settings set by the system properties.
 * Requires Property.PROXY.isSpecified()
 *
 * @return A Selenium proxy object for the current system properties
 */
private Proxy getProxy() {
    Proxy proxy = new Proxy();
    String proxyString = Property.PROXY.getValue().toLowerCase();
    switch (proxyString) {
        case "system":
            proxy.setProxyType(ProxyType.SYSTEM);
            logger.debug("Using system proxy");
            break;
        case "autodetect":
            proxy.setProxyType(ProxyType.AUTODETECT);
            logger.debug("Using autodetect proxy");
            break;
        case "direct":
            proxy.setProxyType(ProxyType.DIRECT);
            logger.debug("Using direct i.e. (no) proxy");
            break;
        default:
            proxy = parseProxyProperty();
            break;
    }
    return proxy;
}
项目:frameworkium-core    文件:AbstractDriver.java   
private Proxy parseProxyProperty() {
    Proxy proxy = new Proxy();
    String proxyString;
    try {
        URI proxyURI = new URI(Property.PROXY.getValue());
        proxyString = String.format("%s:%d", proxyURI.getHost(), proxyURI.getPort());
        proxy.setProxyType(ProxyType.MANUAL)
                .setHttpProxy(proxyString)
                .setFtpProxy(proxyString)
                .setSslProxy(proxyString);
        logger.debug("Set all protocols to use proxy address: {}", proxyString);
    } catch (URISyntaxException e) {
        String message = "Invalid proxy specified, acceptable values are: "
                + "system, autodetect, direct or http://{hostname}:{port}.";
        logger.error(message);
        throw new IllegalArgumentException(message);
    }
    return proxy;
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates an ie webdriver. Unable to use it with a proxy. Causes a crash.
 *
 * @return
 *         An ie webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateIEDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.IE);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating IE driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.IE.getDriverName(), pathWebdriver);

    final DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
    capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
    capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
    capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    capabilities.setCapability("disable-popup-blocking", true);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    return new InternetExplorerDriver(capabilities);
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates a chrome webdriver.
 *
 * @param headlessMode
 *            Enable headless mode ?
 * @return
 *         A chrome webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateGoogleChromeDriver(boolean headlessMode) throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.CHROME);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating Chrome driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);

    final ChromeOptions chromeOptions = new ChromeOptions();
    final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

    setLoggingLevel(capabilities);

    if (Context.isHeadless()) {
        chromeOptions.addArguments("--headless");
    }

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    setChromeOptions(capabilities, chromeOptions);

    String withWhitelistedIps = Context.getWebdriversProperties("withWhitelistedIps");
    if (withWhitelistedIps != null && !"".equals(withWhitelistedIps)) {
        ChromeDriverService service = new ChromeDriverService.Builder().withWhitelistedIps(withWhitelistedIps).withVerbose(false).build();
        return new ChromeDriver(service, capabilities);
    } else {
        return new ChromeDriver(capabilities);
    }
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates a firefox webdriver.
 *
 * @return
 *         A firefox webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateFirefoxDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.FIREFOX);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating Firefox driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver);

    final FirefoxOptions firefoxOptions = new FirefoxOptions();
    final FirefoxBinary firefoxBinary = new FirefoxBinary();

    final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    if (Context.isHeadless()) {
        firefoxBinary.addCommandLineOptions("--headless");
        firefoxOptions.setBinary(firefoxBinary);
    }
    firefoxOptions.setLogLevel(Level.OFF);

    capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, firefoxOptions);

    return new FirefoxDriver(capabilities);
}
项目:satisfy    文件:ProxyFixture.java   
private void setProxyTo(DesiredCapabilities capabilities, Map<String,
        String> proxyProperties) {
    Proxy proxy = new Proxy();
    boolean isEnable = false;
    try {
        String enableParam = System.getProperty("zap.enable");
        isEnable = Boolean.parseBoolean(enableParam);
    } catch (Exception ex) {
        LOGGER.error("\"NullPointerException = \" + ex.getMessage()");
    }


    String host = proxyProperties.get(ProxyProperty.ZAP_PROXY_HOST
            .toString());
    String port = proxyProperties.get(ProxyProperty.ZAP_PROXY_PORT
            .toString());

    if (!isEnable) {
        LOGGER.error("Proxy will not be set: " + " = " + isEnable);
        return;
    }
    proxy.setHttpProxy(host + ":" + port);
    proxy.setSocksProxy(host + ":" + port);
    proxy.setFtpProxy(host + ":" + port);
    proxy.setSslProxy(host + ":" + port);
    proxy.setProxyType(ProxyType.MANUAL);

    capabilities.setCapability(CapabilityType.PROXY, proxy);
}