org.openqa.selenium.Proxy Java Examples

The following examples show how to use org.openqa.selenium.Proxy. 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: UiTestBase.java    From cloud-personslist-scenario with Apache License 2.0 6 votes vote down vote up
private static void setupFirefox() {
	final DesiredCapabilities capabilities = new DesiredCapabilities();
	final String proxyHost = System.getProperty("http.proxyHost");
	final String proxyPort = System.getProperty("http.proxyPort");
	if (proxyHost != null) {
		System.out
				.println("Configuring Firefox Selenium web driver with proxy "
						+ proxyHost
						+ (proxyPort == null ? "" : ":" + proxyPort)
						+ " (requires Firefox browser)");
		final Proxy proxy = new Proxy();
		final String proxyString = proxyHost
				+ (proxyPort == null ? "" : ":" + proxyPort);
		proxy.setHttpProxy(proxyString).setSslProxy(proxyString);
		proxy.setNoProxy("localhost");
		capabilities.setCapability(CapabilityType.PROXY, proxy);
	} else {
		System.out
				.println("Configuring Firefox Selenium web driver without proxy (requires Firefox browser)");
	}

	driver = new FirefoxDriver(capabilities);
	driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
 
Example #2
Source File: ProxyFactoryTest.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreateManualProxy() {
    ProxyHostPort http = new ProxyHostPort("http.com", 1234);
    ProxyHostPort https = new ProxyHostPort("https.com", 1234);
    ProxyHostPort ftp = new ProxyHostPort("ftp", 1234);
    ProxyHostPort socks = new ProxyHostPort("socks", 1234);
    String noProxy = "none";
    Proxy proxy = factory.getManualProxy(http, https, ftp, socks, noProxy);

    assertThat(proxy.getProxyType(), is(Proxy.ProxyType.MANUAL));
    assertThat(proxy.getHttpProxy(), is(http.toUnifiedForm()));
    assertThat(proxy.getSslProxy(), is(https.toUnifiedForm()));
    assertThat(proxy.getFtpProxy(), is(ftp.toUnifiedForm()));
    assertThat(proxy.getSocksProxy(), is(socks.toUnifiedForm()));
    assertThat(proxy.getNoProxy(), is(noProxy));
}
 
Example #3
Source File: ProxyTransform.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Map.Entry<String, Object>> apply(Map.Entry<String, Object> entry) {
  if (!"proxy".equals(entry.getKey())) {
    return singleton(entry);
  }

  Object rawProxy = entry.getValue();
  Map<String, Object> proxy;
  if (rawProxy instanceof Proxy) {
    proxy = new TreeMap<>(((Proxy) rawProxy).toJson());
  } else {
    //noinspection unchecked
    proxy = new TreeMap<>((Map<String, Object>) rawProxy);
  }
  if (proxy.containsKey("proxyType")) {
    proxy.put(
        "proxyType",
        String.valueOf(proxy.get("proxyType")).toLowerCase());
  }
  return singleton(new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), proxy));
}
 
Example #4
Source File: DefaultModule.java    From bromium with MIT License 6 votes vote down vote up
private ProxyDriverIntegrator getProxyDriverIntegrator(RequestFilter recordRequestFilter,
                                                       WebDriverSupplier webDriverSupplier,
                                                       DriverServiceSupplier driverServiceSupplier,
                                                       @Named(PATH_TO_DRIVER) String pathToDriverExecutable,
                                                       @Named(SCREEN) String screen,
                                                       @Named(TIMEOUT) int timeout,
                                                       ResponseFilter responseFilter) throws IOException {
    BrowserMobProxy proxy = createBrowserMobProxy(timeout, recordRequestFilter, responseFilter);
    proxy.start(0);
    logger.info("Proxy running on port " + proxy.getPort());
    Proxy seleniumProxy = createSeleniumProxy(proxy);
    DesiredCapabilities desiredCapabilities = createDesiredCapabilities(seleniumProxy);
    DriverService driverService = driverServiceSupplier.getDriverService(pathToDriverExecutable, screen);
    WebDriver driver = webDriverSupplier.get(driverService, desiredCapabilities);

    return new ProxyDriverIntegrator(driver, proxy, driverService);
}
 
Example #5
Source File: WebDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
/**
 * Call this method to create a {@link Proxy} instance for use when creating a {@link org.openqa.selenium.WebDriver}
 * instance.  The values/settings of the proxy depends entirely on the values set on this config instance.
 *
 * @return a {@link Proxy}
 */
public Proxy createProxy() {
    switch (getProxyType()) {
        case PROXY_PAC:
            return proxyFactory.getConfigUrlProxy(getProxyPacUrl());
        case DIRECT:
            return proxyFactory.getDirectProxy();
        case AUTO_DETECT:
            return proxyFactory.getAutodetectProxy();
        case MANUAL:
            if (isUseHttpSettingsForAllProtocols()) {
                ProxyHostPort proxy = new ProxyHostPort(getHttpHost(), getHttpPort());
                return proxyFactory.getManualProxy(proxy, proxy, proxy, proxy, getNoProxyHost());
            }
            ProxyHostPort http = new ProxyHostPort(getHttpHost(), getHttpPort());
            ProxyHostPort https = new ProxyHostPort(getHttpsHost(), getHttpsPort());
            ProxyHostPort ftp = new ProxyHostPort(getFtpHost(), getFtpPort());
            ProxyHostPort socks = new ProxyHostPort(getSocksHost(), getSocksPort());
            return proxyFactory.getManualProxy(http, https, ftp, socks, getNoProxyHost());
        default:
            return proxyFactory.getSystemProxy();
    }
}
 
Example #6
Source File: WebDriverConfigTest.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDelegateToProxyFactoryWhenCreatingManualProxyWithAllValuesSpecified() {
    final ProxyHostPort http = new ProxyHostPort("http", 1);
    final ProxyHostPort https = new ProxyHostPort("https", 2);
    final ProxyHostPort ftp = new ProxyHostPort("ftp", 3);
    final ProxyHostPort socks = new ProxyHostPort("socks", 4);
    final String noProxy = "host1, host2";
    config.setHttpHost(http.getHost());
    config.setHttpPort(http.getPort());
    config.setUseHttpSettingsForAllProtocols(false);
    config.setHttpsHost(https.getHost());
    config.setHttpsPort(https.getPort());
    config.setFtpHost(ftp.getHost());
    config.setFtpPort(ftp.getPort());
    config.setSocksHost(socks.getHost());
    config.setSocksPort(socks.getPort());
    config.setNoProxyHost(noProxy);
    when(proxyFactory.getManualProxy(http, https, ftp, socks, noProxy)).thenReturn(new Proxy());
    config.setProxyType(ProxyType.MANUAL);

    Proxy proxy = config.createProxy();

    assertThat(proxy, is(notNullValue()));
    verify(proxyFactory, times(1)).getManualProxy(http, https, ftp, socks, noProxy);
}
 
Example #7
Source File: WebDriverConfigTest.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDelegateToProxyFactoryWhenCreatingManualProxyWithHttpAsDefault() {
    final ProxyHostPort http = new ProxyHostPort("http", 1);
    final String noProxy = "host1, host2";
    config.setHttpHost(http.getHost());
    config.setHttpPort(http.getPort());
    config.setUseHttpSettingsForAllProtocols(true);
    config.setNoProxyHost(noProxy);
    when(proxyFactory.getManualProxy(http, http, http, http, noProxy)).thenReturn(new Proxy());
    config.setProxyType(ProxyType.MANUAL);

    Proxy proxy = config.createProxy();

    assertThat(proxy, is(notNullValue()));
    verify(proxyFactory, times(1)).getManualProxy(http, http, http, http, noProxy);
}
 
Example #8
Source File: JsonOutputTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConvertAProxyCorrectly() {
  Proxy proxy = new Proxy();
  proxy.setHttpProxy("localhost:4444");

  MutableCapabilities caps = new DesiredCapabilities("foo", "1", Platform.LINUX);
  caps.setCapability(CapabilityType.PROXY, proxy);
  Map<String, ?> asMap = ImmutableMap.of("desiredCapabilities", caps);
  Command command = new Command(new SessionId("empty"), DriverCommand.NEW_SESSION, asMap);

  String json = convert(command.getParameters());

  JsonObject converted = new JsonParser().parse(json).getAsJsonObject();
  JsonObject capsAsMap = converted.get("desiredCapabilities").getAsJsonObject();

  assertThat(capsAsMap.get(CapabilityType.PROXY).getAsJsonObject().get("httpProxy").getAsString())
      .isEqualTo(proxy.getHttpProxy());
}
 
Example #9
Source File: ProxyBasedIT.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 6 votes vote down vote up
@Test
public void usingAProxyToTrackNetworkTrafficStep2() {
    BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
    browserMobProxy.start();
    Proxy seleniumProxyConfiguration = ClientUtil.createSeleniumProxy(browserMobProxy);

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability(CapabilityType.PROXY, seleniumProxyConfiguration);
    driver = new FirefoxDriver(firefoxOptions);
    browserMobProxy.newHar();
    driver.get("https://www.google.co.uk");

    Har httpArchive = browserMobProxy.getHar();

    assertThat(getHTTPStatusCode("https://www.google.co.uk/", httpArchive))
            .isEqualTo(200);
}
 
Example #10
Source File: SeleniumProxyFactory.java    From frameworkium-core with Apache License 2.0 6 votes vote down vote up
/**
 * Valid inputs are system, autodetect, direct or http://{hostname}:{port}
 *
 * <p>This does not currently cope with PAC (Proxy auto-configuration from URL)
 *
 * @param proxyProperty the string representing the proxy required
 * @return a Selenium {@link Proxy} representation of proxyProperty
 */
public static Proxy createProxy(String proxyProperty) {
    Proxy proxy = new Proxy();
    switch (proxyProperty.toLowerCase()) {
        case "system":
            logger.debug("Using system proxy");
            proxy.setProxyType(Proxy.ProxyType.SYSTEM);
            break;
        case "autodetect":
            logger.debug("Using autodetect proxy");
            proxy.setProxyType(Proxy.ProxyType.AUTODETECT);
            break;
        case "direct":
            logger.debug("Using direct i.e. (no) proxy");
            proxy.setProxyType(Proxy.ProxyType.DIRECT);
            break;
        default:
            return createManualProxy(proxyProperty);
    }
    return proxy;
}
 
Example #11
Source File: BaseTest.java    From at.info-knowledge-base with MIT License 6 votes vote down vote up
private void configureProxy(final ITestContext context, final Method method) {
    final MonitorNetwork monitorNetwork = method.getAnnotation(MonitorNetwork.class);

    if (monitorNetwork != null && monitorNetwork.enabled()) {
        final String initialPageID = context.getName() + " : " + method.getName();
        harDetailsLink = HAR_STORAGE.getHarDetailsURL(initialPageID);

        proxy = new BrowserMobProxy(PROXY_IP, PROXY_PORT);
        proxy.setSocketOperationTimeout(DEFAULT_SOCKET_TIMEOUT);
        proxy.setRequestTimeout(DEFAULT_REQUEST_TIMEOUT);

        // Getting port for Selenium proxy
        final int port = proxy.getPort();
        proxy.setPort(port);

        // Creating har on raised proxy for monitoring net statistics before first page is loaded.
        proxy.newHar(initialPageID, monitorNetwork.captureHeaders(), monitorNetwork.captureContent(),
                monitorNetwork.captureBinaryContent());

        // Get the Selenium proxy object
        final String actualProxy = PROXY_IP + ":" + port;
        seleniumProxy = new Proxy();
        seleniumProxy.setHttpProxy(actualProxy).setFtpProxy(actualProxy)
                .setSslProxy(actualProxy);
    }
}
 
Example #12
Source File: ProxyServer.java    From odo with Apache License 2.0 5 votes vote down vote up
public org.openqa.selenium.Proxy seleniumProxy() throws UnknownHostException {
    Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.MANUAL);
    String proxyStr = String.format("%s:%d", getLocalHost().getCanonicalHostName(), getPort());
    proxy.setHttpProxy(proxyStr);
    proxy.setSslProxy(proxyStr);

    return proxy;
}
 
Example #13
Source File: InitialSetupHooks.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Создает настойки прокси для запуска драйвера
 */
@Before(order = 1)
public void setDriverProxy() {
    if (!Strings.isNullOrEmpty(System.getProperty("proxy"))) {
        Proxy proxy = new Proxy().setHttpProxy(System.getProperty("proxy"));
        setProxy(proxy);
        log.info("Проставлена прокси: " + proxy);
    }
}
 
Example #14
Source File: ProxyFactoryTest.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateAnAutoDetectProxy() {
    Proxy proxy = factory.getAutodetectProxy();

    assertThat(proxy.getProxyType(), is(Proxy.ProxyType.AUTODETECT));
    assertThat(proxy.isAutodetect(), is(true));
}
 
Example #15
Source File: AbstractRealBrowserDriver.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
private void setFirefoxProxyIfAvailable(
                                         DesiredCapabilities capabilities ) {

    if (!StringUtils.isNullOrEmpty(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST)
        && !StringUtils.isNullOrEmpty(AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT)) {

        capabilities.setCapability(CapabilityType.PROXY,
                                   new Proxy().setHttpProxy(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST
                                                            + ':'
                                                            + AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT));
    }
}
 
Example #16
Source File: BrowserRunnerHelper.java    From neodymium-library with MIT License 5 votes vote down vote up
public static Proxy createProxyCapabilities()
{
    final String proxyHost = Neodymium.configuration().getProxyHost() + ":" + Neodymium.configuration().getProxyPort();

    final Proxy webdriverProxy = new Proxy();
    webdriverProxy.setHttpProxy(proxyHost);
    webdriverProxy.setSslProxy(proxyHost);
    webdriverProxy.setFtpProxy(proxyHost);
    if (!StringUtils.isAllEmpty(Neodymium.configuration().getProxySocketUsername(), Neodymium.configuration().getProxySocketPassword())
        || Neodymium.configuration().getProxySocketVersion() != null)
    {
        webdriverProxy.setSocksProxy(proxyHost);
        if (StringUtils.isNoneEmpty(Neodymium.configuration().getProxySocketUsername(),
                                    Neodymium.configuration().getProxySocketPassword()))
        {
            webdriverProxy.setSocksUsername(Neodymium.configuration().getProxySocketUsername());
            webdriverProxy.setSocksPassword(Neodymium.configuration().getProxySocketPassword());
        }
        if (Neodymium.configuration().getProxySocketVersion() != null)
        {
            webdriverProxy.setSocksVersion(4);
        }
    }

    webdriverProxy.setNoProxy(Neodymium.configuration().getProxyBypass());
    return webdriverProxy;
}
 
Example #17
Source File: BaseTest.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
private DesiredCapabilities getDesireCapabilities() {
    final DesiredCapabilities capability = new DesiredCapabilities();

    if (proxy != null && seleniumProxy != null) {
        capability.setCapability(CapabilityType.PROXY, seleniumProxy);
    } else {
        final Proxy noProxy = new Proxy();
        noProxy.setProxyType(Proxy.ProxyType.DIRECT);
        capability.setCapability(CapabilityType.PROXY, noProxy);
    }

    return capability;
}
 
Example #18
Source File: NewSessionPayload.java    From selenium with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> convertOssToW3C(Map<String, Object> capabilities) {
  if (capabilities == null) {
    return null;
  }

  Map<String, Object> toReturn = new TreeMap<>(capabilities);

  // Platform name
  if (capabilities.containsKey(PLATFORM) && !capabilities.containsKey(PLATFORM_NAME)) {
    toReturn.put(PLATFORM_NAME, String.valueOf(capabilities.get(PLATFORM)));
  }

  if (capabilities.containsKey(PROXY)) {
    Map<String, Object> proxyMap;
    Object rawProxy = capabilities.get(CapabilityType.PROXY);
    if (rawProxy instanceof Proxy) {
      proxyMap = ((Proxy) rawProxy).toJson();
    } else if (rawProxy instanceof Map) {
      proxyMap = (Map<String, Object>) rawProxy;
    } else {
      proxyMap = new HashMap<>();
    }
    if (proxyMap.containsKey("noProxy")) {
      Map<String, Object> w3cProxyMap = new HashMap<>(proxyMap);
      Object rawData = proxyMap.get("noProxy");
      if (rawData instanceof String) {
        w3cProxyMap.put("noProxy", Arrays.asList(((String) rawData).split(",\\s*")));
      }
      toReturn.put(CapabilityType.PROXY, w3cProxyMap);
    }
  }

  return toReturn;
}
 
Example #19
Source File: AbstractCapabilities.java    From carina with Apache License 2.0 5 votes vote down vote up
protected DesiredCapabilities initBaseCapabilities(DesiredCapabilities capabilities, String browser, String testName) {

        // TODO: should use provide capabilities as an argument for getPlatform call below?
        String platform = Configuration.getPlatform();
        if (!platform.equals("*")) {
            capabilities.setPlatform(Platform.extractFromSysProperty(platform));
        }

        capabilities.setBrowserName(browser);

        // Selenium 3.4 doesn't support '*'. Only explicit or empty browser version should be provided
        String browserVersion = Configuration.get(Parameter.BROWSER_VERSION);
        if ("*".equalsIgnoreCase(browserVersion)) {
            browserVersion = "";
        }
        capabilities.setVersion(browserVersion);
        capabilities.setCapability("name", testName);

        Proxy proxy = setupProxy();
        if (proxy != null) {
            capabilities.setCapability(CapabilityType.PROXY, proxy);
        }

        // add capabilities based on dynamic _config.properties variables
        capabilities = initCapabilities(capabilities);
        
        return capabilities;
    }
 
Example #20
Source File: BaseBrowserFactory.java    From webtester-core with Apache License 2.0 5 votes vote down vote up
protected void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
    if (proxyConfiguration != null && !(proxyConfiguration instanceof NoProxyConfiguration)) {
        Proxy proxy = new Proxy();
        proxyConfiguration.configureProxy(proxy);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }
}
 
Example #21
Source File: DefaultModule.java    From bromium with MIT License 5 votes vote down vote up
public DesiredCapabilities createDesiredCapabilities(Proxy proxy) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--test-type");
    options.addArguments("--start-maximized");
    options.addArguments("--disable-web-security");
    options.addArguments("--allow-file-access-from-files");
    options.addArguments("--allow-running-insecure-content");
    options.addArguments("--allow-cross-origin-auth-prompt");
    options.addArguments("--allow-file-access");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return capabilities;
}
 
Example #22
Source File: ExtensionSelenium.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private static void setCommonOptions(
        MutableCapabilities capabilities, String proxyAddress, int proxyPort) {
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    // W3C capability
    capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

    if (proxyAddress != null) {
        String httpProxy = proxyAddress + ":" + proxyPort;
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(httpProxy);
        proxy.setSslProxy(httpProxy);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }
}
 
Example #23
Source File: CustomDriverProvider.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * если установлен -Dproxy=true стартует прокси
 * har для прослушки указывается в application.properties
 * @param capabilities
 */
private void enableProxy(DesiredCapabilities capabilities) {
    proxy.setTrustAllServers(Boolean.valueOf(loadProperty(TRUST_ALL_SERVERS, "true")));
    proxy.start();

    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

    capabilities.setCapability(PROXY, seleniumProxy);
    capabilities.setCapability(ACCEPT_SSL_CERTS, Boolean.valueOf(loadProperty(ACCEPT_SSL_CERTS, "true")));
    capabilities.setCapability(SUPPORTS_JAVASCRIPT, Boolean.valueOf(loadProperty(SUPPORTS_JAVASCRIPT, "true")));

    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_CONTENT, CaptureType.RESPONSE_HEADERS);
    proxy.newHar(loadProperty(NEW_HAR));
}
 
Example #24
Source File: AbstractProxyTest.java    From bobcat with Apache License 2.0 5 votes vote down vote up
DesiredCapabilities proxyCapabilities(BrowserMobProxy browserMobProxy) {
  browserMobProxy.enableHarCaptureTypes(
      CaptureType.REQUEST_HEADERS,
      CaptureType.RESPONSE_HEADERS,
      CaptureType.REQUEST_CONTENT,
      CaptureType.RESPONSE_CONTENT);

  Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy);
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
  return capabilities;
}
 
Example #25
Source File: EnableProxy.java    From bobcat with Apache License 2.0 5 votes vote down vote up
private DesiredCapabilities enableProxy(Capabilities capabilities) {
  DesiredCapabilities caps = new DesiredCapabilities(capabilities);
  try {
    InetAddress proxyInetAddress = InetAddress.getByName(proxyIp);
    BrowserMobProxy browserMobProxy = proxyController.startProxyServer(proxyInetAddress);
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy, proxyInetAddress);
    caps.setCapability(CapabilityType.PROXY, seleniumProxy);
  } catch (UnknownHostException e) {
    throw new IllegalStateException(e);
  }
  return caps;
}
 
Example #26
Source File: SeleniumProxyFactory.java    From frameworkium-core with Apache License 2.0 5 votes vote down vote up
private static Proxy createManualProxy(String proxyProperty) {
    String proxyString = getProxyURL(proxyProperty);
    logger.debug("All protocols to use proxy address: {}", proxyString);
    Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.MANUAL)
            .setHttpProxy(proxyString)
            .setFtpProxy(proxyString)
            .setSslProxy(proxyString);
    return proxy;
}
 
Example #27
Source File: RemoteFactory.java    From webtester2-core with Apache License 2.0 5 votes vote down vote up
private void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
    if (proxyConfiguration != null) {
        Proxy proxy = new Proxy();
        proxyConfiguration.configureProxy(proxy);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }
}
 
Example #28
Source File: BaseBrowserFactory.java    From webtester2-core with Apache License 2.0 5 votes vote down vote up
protected void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
    if (proxyConfiguration != null && !(proxyConfiguration instanceof NoProxyConfiguration)) {
        Proxy proxy = new Proxy();
        proxyConfiguration.configureProxy(proxy);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }
}
 
Example #29
Source File: SafariCapabilitiesFactory.java    From seleniumtestsframework with Apache License 2.0 5 votes vote down vote up
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    DesiredCapabilities capability = null;
    capability = DesiredCapabilities.safari();

    if (cfg.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (cfg.getBrowserVersion() != null) {
        capability.setVersion(cfg.getBrowserVersion());
    }

    if (cfg.getWebPlatform() != null) {
        capability.setPlatform(cfg.getWebPlatform());
    }

    if (cfg.getProxyHost() != null) {
        Proxy proxy = cfg.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    return capability;
}
 
Example #30
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setUpProxy(FirefoxProfile firefoxProfile) {
    if (!StringUtils.isEmpty(proxyPort) && !StringUtils.isEmpty(proxyHost)) {
        StringBuilder strb = new StringBuilder(proxyHost);
        strb.append(":");
        strb.append(proxyPort);
        Proxy proxy = new Proxy();
        proxy.setFtpProxy(strb.toString());
        proxy.setHttpProxy(strb.toString());
        proxy.setSslProxy(strb.toString());
        if (StringUtils.isNotEmpty(proxyExclusionUrl)) {
            proxy.setNoProxy(proxyExclusionUrl.replaceAll(";", ","));
        }
        firefoxProfile.setProxyPreferences(proxy);
    }
}