private Proxy getProxy() { ProxyServer server = getServer(); server.setCaptureContent(true); server.setCaptureHeaders(true); SeleniumHolder.setProxyServer(server); Proxy proxy = new Proxy(); try { proxy = server.seleniumProxy(); String localIp = InetAddress.getLocalHost().getHostAddress(); String proxyStr = String.format("%s:%d", localIp, server.getPort()); proxy.setHttpProxy(proxyStr); proxy.setSslProxy("trustAllSSLCertificates"); proxy.setFtpProxy(proxyStr); SeleniumHolder.setProxy(proxy); } catch (UnknownHostException e) { LOGGER.error("UnknownHostException occurs", e); } return proxy; }
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); }
public static PhantomJSDriverService createDefaultService(Capabilities desiredCapabilities, Map<String, String> env) { Proxy proxy = null; if (desiredCapabilities != null) { proxy = Proxy.extractFrom(desiredCapabilities); } File phantomjsfile = findPhantomJS(desiredCapabilities, "https://github.com/ariya/phantomjs/wiki", "http://phantomjs.org/download.html"); File ghostDriverfile = findGhostDriver(desiredCapabilities, "https://github.com/detro/ghostdriver/blob/master/README.md", "https://github.com/detro/ghostdriver/downloads"); Builder builder = new Builder(); builder.usingPhantomJSExecutable(phantomjsfile) .usingGhostDriver(ghostDriverfile) .usingAnyFreePort() .withProxy(proxy) .withLogFile(new File("phantomjsdriver.log")) .usingCommandLineArguments(findCLIArgumentsFromCaps(desiredCapabilities, "phantomjs.cli.args")) .usingGhostDriverCommandLineArguments(findCLIArgumentsFromCaps(desiredCapabilities, "phantomjs.ghostdriver.cli.args")); if(null != env) builder.withEnvironment(env); return builder.build(); }
private WebDriver getWebClient(int portForJSCoverProxy) { Proxy proxy = new Proxy().setHttpProxy("localhost:" + portForJSCoverProxy); DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(CapabilityType.PROXY, proxy); caps.setJavascriptEnabled(true); caps.setBrowserName(BrowserType.HTMLUNIT); return new HtmlUnitDriver(caps) { @Override protected WebClient modifyWebClient(WebClient client) { client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> { if(removeJsSnippets != null && !removeJsSnippets.isEmpty()) { for(String toReplace : removeJsSnippets) { sourceCode = sourceCode.replace(toReplace, ""); } return sourceCode; } else { return sourceCode; } }); return client; } }; }
@Override public WebCommunicationWrapper createWebDriver(ProxyServerWrapper proxyServer) throws WorkerException { try { Proxy proxy = proxyServer.seleniumProxy(); proxyServer.setCaptureContent(true); proxyServer.setCaptureHeaders(true); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.PROXY, proxy); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); FirefoxProfile fp = getFirefoxProfile(); fp.setAcceptUntrustedCertificates(true); fp.setAssumeUntrustedCertificateIssuer(false); capabilities.setCapability(AetFirefoxDriver.PROFILE, fp); return new WebCommunicationWrapperImpl(getFirefoxDriver(fp, capabilities), proxyServer, requestExecutorFactory .createInstance()); } catch (Exception e) { throw new WorkerException(e.getMessage(), e); } }
protected JFunkHtmlUnitDriverImpl(final BrowserVersion browserVersion, final HtmlUnitWebDriverParams webDriverParams, final AjaxController ajaxController, final HtmlUnitSSLParams sslParams, final Map<String, CredentialsProvider> credentialsProviderMap, final Provider<DumpFileCreator> htmlFileCreatorProvider, final Provider<File> moduleArchiveDirProvider, final Provider<Set<WebWindowListener>> listenersProvider, final Proxy proxy) { super(browserVersion); this.webDriverParams = webDriverParams; this.sslParams = sslParams; this.ajaxController = ajaxController; this.credentialsProviderMap = credentialsProviderMap; this.htmlFileCreatorProvider = htmlFileCreatorProvider; this.moduleArchiveDirProvider = moduleArchiveDirProvider; this.listenersProvider = listenersProvider; setProxy(proxy); setJavascriptEnabled(webDriverParams.isJavascriptEnabled()); // cannot override modifyWebClient because it is called in the super class' constructor before our params are set configureWebClient(getWebClient()); }
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); }
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); } }
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)); } }
@Override public CapabilitiesBuilder addProxy(String host, int port) { Proxy proxy = new Proxy(); proxy.setHttpProxy("host" + ":" + port); capabilities.setCapability("proxy", proxy); return this; }
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); }
public ZAProxyScanner(String host, int port, String apiKey) throws IllegalArgumentException, ProxyException { validateHost(host); validatePort(port); this.apiKey = apiKey; clientApi = new ClientApi(host, port, this.apiKey); validateMinimumRequiredZapVersion(); seleniumProxy = new Proxy(); seleniumProxy.setProxyType(Proxy.ProxyType.PAC); StringBuilder strBuilder = new StringBuilder(); strBuilder.append("http://").append(host).append(":").append(port).append("/proxy.pac?apikey=").append(this.apiKey); seleniumProxy.setProxyAutoconfigUrl(strBuilder.toString()); }
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; }
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; }
private void setOptionalProxyConfiguration(DesiredCapabilities capabilities) { if (proxyConfiguration != null) { Proxy proxy = new Proxy(); proxyConfiguration.configureProxy(proxy); capabilities.setCapability(CapabilityType.PROXY, proxy); } }
protected void setOptionalProxyConfiguration(DesiredCapabilities capabilities) { if (proxyConfiguration != null && !(proxyConfiguration instanceof NoProxyConfiguration)) { Proxy proxy = new Proxy(); proxyConfiguration.configureProxy(proxy); capabilities.setCapability(CapabilityType.PROXY, proxy); } }
public static WebDriver initChromeDriver(String ip,int prot) { logger.info("start init WebDriver!"); WebDriver driver = null; String proxyIpAndProt = ip+":"+prot; try { /*ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(new File("e:\\app\\chromedriver\\chromedriver.exe")).usingAnyFreePort() .build(); service.start();*/ //System.setProperty("webdriver.chrome.driver", "e:\\app\\chromedriver\\chromedriver.exe"); System.setProperty("webdriver.chrome.driver", "D:\\workspace\\alimama\\alimama\\chromedriver\\chromedriver.exe"); DesiredCapabilities capabilities = new DesiredCapabilities(); Proxy proxy = new Proxy(); proxy.setHttpProxy(proxyIpAndProt).setFtpProxy(proxyIpAndProt).setSocksProxy(proxyIpAndProt).setSslProxy(proxyIpAndProt); capabilities.setCapability(CapabilityType.ForSeleniumServer.AVOIDING_PROXY, true); capabilities.setCapability(CapabilityType.ForSeleniumServer.ONLY_PROXYING_SELENIUM_TRAFFIC, true); capabilities.setCapability(CapabilityType.PROXY, proxy); driver = new ChromeDriver(capabilities); //driver = new HtmlUnitDriver(true); } catch (Exception e) { logger.error("Init WebDriver is error!", e); throw new RuntimeException(e); } logger.info("init WebDriver is success!"); return driver; }
/** * This is a quick test from nasis that exhibits different behavior from * unit tests because unit tests call System.exit(). The stop method should * stop all non-daemon threads and should cause the JVM to exit without * explicitly calling System.exit(), which running as an application * properly tests. */ public static void main(final String[] args) throws Exception { HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap() .withPort(0) .start(); Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); String proxyStr = String.format("localhost:%d", proxyServer.getListenAddress().getPort()); proxy.setHttpProxy(proxyStr); proxy.setSslProxy(proxyStr); DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setCapability(CapabilityType.PROXY, proxy); String urlString = "http://www.yahoo.com/"; WebDriver driver = new FirefoxDriver(capability); driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.get(urlString); driver.close(); System.out.println("Driver closed"); proxyServer.abort(); System.out.println("Proxy stopped"); }
public void testWithWebDriver() throws Exception { HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap() .withPort(0) .start(); Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); String proxyStr = String.format("localhost:%d", proxyServer.getListenAddress().getPort()); proxy.setHttpProxy(proxyStr); proxy.setSslProxy(proxyStr); DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setCapability(CapabilityType.PROXY, proxy); final String urlString = "http://www.yahoo.com/"; // Note this will actually launch a browser!! final WebDriver driver = new FirefoxDriver(capability); driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.get(urlString); final String source = driver.getPageSource(); // Just make sure it got something within reason. assertThat(source.length(), greaterThan(100)); driver.close(); proxyServer.abort(); }
/** * <p> * remote.public.driver set to chrome or firefox (null assumes firefox). * </p><p> * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid) * if proxy.host is set, the web driver is setup to use a proxy * </p> * * @return WebDriver or null if unable to create */ public static WebDriver getWebDriver() { String driverParam = System.getProperty(HUB_DRIVER_PROPERTY); String hubParam = System.getProperty(HUB_PROPERTY); String proxyParam = System.getProperty(PROXY_HOST_PROPERTY); // setup proxy if specified as VM Arg DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver webDriver = null; if (StringUtils.isNotEmpty(proxyParam)) { capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam)); } if (hubParam == null) { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); return new FirefoxDriver(capabilities); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new ChromeDriver(capabilities); } else if ("safari".equals(driverParam)) { System.out.println("SafariDriver probably won't work, if it does please contact Erik M."); return new SafariDriver(capabilities); } } else { try { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox()); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome()); } } catch (MalformedURLException mue) { System.out.println(getHubUrlString() + " " + mue.getMessage()); mue.printStackTrace(); } } return null; }
public void setUp() throws Exception { Proxy proxy = new Proxy(); proxy.setHttpProxy("localhost:8090"); proxy.setFtpProxy("localhost:8090"); proxy.setSslProxy("localhost:8090"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.PROXY, proxy); driver = new FirefoxDriver(capabilities); this.setDriver(driver); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
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; }
public DesiredCapabilities createCapabilities(final DriverConfig webDriverConfig) { DesiredCapabilities capability = null; capability = DesiredCapabilities.htmlUnit(); if (webDriverConfig.isEnableJavascript()) { capability.setJavascriptEnabled(true); } else { capability.setJavascriptEnabled(false); } capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true); capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); if (webDriverConfig.getBrowserVersion() != null) { capability.setVersion(webDriverConfig.getBrowserVersion()); } if (webDriverConfig.getWebPlatform() != null) { capability.setPlatform(webDriverConfig.getWebPlatform()); } if (webDriverConfig.getProxyHost() != null) { Proxy proxy = webDriverConfig.getProxy(); capability.setCapability(CapabilityType.PROXY, proxy); } return capability; }
public DesiredCapabilities createCapabilities(final DriverConfig cfg) { DesiredCapabilities capability = new DesiredCapabilities(); capability.setBrowserName(DesiredCapabilities.phantomjs().getBrowserName()); 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; }
/** * This is a quick test from nasis that exhibits different behavior from * unit tests because unit tests call System.exit(). The stop method should * stop all non-daemon threads and should cause the JVM to exit without * explicitly calling System.exit(), which running as an application * properly tests. */ public static void main(final String[] args) throws Exception { int port = 9090; HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap() .withPort(port) .start(); Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); String proxyStr = String.format("localhost:%d", port); proxy.setHttpProxy(proxyStr); proxy.setSslProxy(proxyStr); DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setCapability(CapabilityType.PROXY, proxy); String urlString = "http://www.yahoo.com/"; WebDriver driver = new FirefoxDriver(capability); driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.get(urlString); driver.close(); System.out.println("Driver closed"); proxyServer.stop(); System.out.println("Proxy stopped"); }
public void testWithWebDriver() throws Exception { int port = 9090; HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap() .withPort(port) .start(); Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); String proxyStr = String.format("localhost:%d", port); proxy.setHttpProxy(proxyStr); proxy.setSslProxy(proxyStr); DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setCapability(CapabilityType.PROXY, proxy); final String urlString = "http://www.yahoo.com/"; // Note this will actually launch a browser!! final WebDriver driver = new FirefoxDriver(capability); driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); driver.get(urlString); final String source = driver.getPageSource(); // Just make sure it got something within reason. assertTrue(source.length() > 100); driver.close(); proxyServer.stop(); }
public void run() { Proxy proxy = new Proxy(); proxy.setNoProxy(Configuracoes.getNoProxyURL()); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY, proxy); try { carregarJanela(cap, cont); } catch (Exception e) { e.printStackTrace(); } }
public void run() { Proxy proxy = new Proxy(); proxy.setNoProxy(Configuracoes.getNoProxyURL()); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY, proxy); try { carregarJanela(cap); } catch (Exception e) { e.printStackTrace(); } }
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; }
private void setProxy(final Proxy proxy) { if (proxy != null) { String fullProxy = proxy.getHttpProxy(); if (fullProxy != null) { int index = fullProxy.indexOf(":"); if (index != -1) { String host = fullProxy.substring(0, index); int port = Integer.parseInt(fullProxy.substring(index + 1)); setProxy(host, port); } else { setProxy(fullProxy, 0); } } } }
private Proxy createProxyFromConfig(final Configuration config) { Map<String, String> proxyConfig = newHashMap(); for (Entry<String, String> entry : config.entrySet()) { String key = entry.getKey(); if (key.startsWith(PROXY_PREFIX)) { proxyConfig.put(substringAfter(key, PROXY_PREFIX), entry.getValue()); } } if (proxyConfig.isEmpty()) { return null; } return new Proxy(proxyConfig); }
@Test public void testGet() throws IOException { Configuration config = new Configuration(Charsets.UTF_8); Reader reader = null; try { reader = Resources.newReaderSupplier(Resources.getResource("test_capabilities.properties"), Charsets.UTF_8) .getInput(); config.load(reader); CapabilitiesProvider provider = new CapabilitiesProvider(Providers.of(config)); Map<String, DesiredCapabilities> capabilitiesMap = provider.get(); assertThat(capabilitiesMap).hasSize(2); assertThat(capabilitiesMap).containsKey("firefox"); assertThat(capabilitiesMap).containsKey("remote"); Capabilities capabilities = capabilitiesMap.get("firefox"); assertThat(capabilities.getCapability("globalCapability")).isEqualTo("globalCapabilityValueOverride"); assertThat(capabilities.getCapability("firefoxCapability")).isEqualTo("firefoxCapabilityValue"); capabilities = capabilitiesMap.get("remote"); assertThat(capabilities.getCapability("globalCapability")).isEqualTo("globalCapabilityValue"); assertThat(capabilities.getCapability("stringCapability")).isEqualTo("stringCapabilityValue"); assertThat(capabilities.getCapability("listCapability")).isInstanceOf(List.class); @SuppressWarnings("unchecked") List<String> list = (List<String>) capabilities.getCapability("listCapability"); assertThat(list).contains("listCapabilityValue1", "listCapabilityValue2"); Object proxy = capabilities.getCapability(CapabilityType.PROXY); assertThat(proxy).isInstanceOf(Proxy.class); assertThat(((Proxy) proxy).getHttpProxy()).isEqualTo("localhost:8080"); } finally { closeQuietly(reader); } }
@Test public void testGetWithProxyOnly() { Configuration config = new Configuration(Charsets.UTF_8); String proxyString = "localhost:8080"; config.put("webdriver.proxy.httpProxy", proxyString); CapabilitiesProvider provider = new CapabilitiesProvider(Providers.of(config)); Capabilities capabilities = provider.get().get("anykey"); Object proxy = capabilities.getCapability(CapabilityType.PROXY); assertThat(proxy).isInstanceOf(Proxy.class); assertThat(((Proxy) proxy).getHttpProxy()).isEqualTo(proxyString); }
@Override public DriverService createDriverService() { Builder builder = new PhantomJSDriverService.Builder(); if (driverExecutable != null) builder.usingPhantomJSExecutable(driverExecutable); if (ghostDriver != null) builder.usingGhostDriver(ghostDriver); if (port != null) builder.usingPort(port); if (environment != null) builder.withEnvironment(environment); if (logFile != null) builder.withLogFile(logFile); if (proxy != null) builder.withProxy(new Proxy(proxy)); if (commandLineArguments != null) builder.usingCommandLineArguments(commandLineArguments); if (ghostDriverCommandLineArguments != null) builder.usingGhostDriverCommandLineArguments(ghostDriverCommandLineArguments); return builder.build(); }
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); } }