daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /**
  2.      * !!!!! NOTE - now work only with Chrome and HTTP proxy
  3.      * Will be update to working with FF and Socks5 proxy
  4.      * This method was tested on Docker Selenium nodes
  5.      * @param remoteWebDriverURL - url on selenium grid hub(e.g. http://10.10.82.142:4444/wd/hub)/ All project's hub addresses can be found in 'properties' file
  6.      * @param browserName - chrome or firefox
  7.      * @param proxy_ip - ip without port
  8.      * @param port - port as integer
  9.      * @return remote WebDriver
  10.      */
  11.     public  static WebDriver initRemoteWebDriverWithProxy(String remoteWebDriverURL, String browserName, String proxy_ip, int port) {
  12.         try {
  13.             DesiredCapabilities capability = DesiredCapabilities.chrome();
  14.             Proxy proxy = new Proxy();
  15.             String ProxyString = proxy_ip + ":" + port;
  16.             proxy.setProxyType(Proxy.ProxyType.MANUAL);
  17.             proxy.setHttpProxy(ProxyString)
  18.                     .setFtpProxy(ProxyString)
  19.                     .setSocksProxy(ProxyString)
  20.                     .setSslProxy(ProxyString);
  21.             capability.setCapability(CapabilityType.PROXY, proxy);
  22.             capability.setBrowserName(browserName);
  23.             capability.setCapability(CapabilityType.PROXY, proxy);
  24.             WebDriver driver = new RemoteWebDriver(new URL(remoteWebDriverURL), capability);
  25.             driver.manage().window().maximize();
  26.             return driver;
  27.         } catch (MalformedURLException e) {
  28.             e.printStackTrace();
  29.             return null;
  30.         }
  31.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top