ponder6168

BrowserMob with Selinium for Chrome

Jun 14th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. browserMobProxy = getProxyServer(username, password);
  2. Proxy seleniumProxy = getSeleniumProxy(browserMobProxy);
  3. System.setProperty("webdriver.chrome.driver","P:/AppDev/MIS Projects/Selenium/chromedriver.exe");
  4. ChromeOptions chromeOptions = new ChromeOptions();
  5. chromeOptions.addArguments("user-data-dir=" + profileLocation);
  6. chromeOptions.addArguments("disable-infobars");
  7. chromeOptions.setCapability(CapabilityType.PROXY, seleniumProxy);
  8.  
  9. private static BrowserMobProxy getProxyServer(String username, String password) {
  10. BrowserMobProxy proxy = new BrowserMobProxyServer();
  11. proxy.setTrustAllServers(true);
  12. proxy.start();
  13. String credentials = username + ":" + password;
  14. String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString(credentials.getBytes()));
  15. proxy.addHeader("Authorization", encodedCreadentials);
  16. return proxy;
  17. }
  18.  
  19. public static Proxy getSeleniumProxy(BrowserMobProxy proxyServer) {
  20. Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyServer);
  21. try {
  22. String hostIp = Inet4Address.getLocalHost().getHostAddress();
  23. seleniumProxy.setHttpProxy(hostIp + ":" + proxyServer.getPort());
  24. seleniumProxy.setSslProxy(hostIp + ":" + proxyServer.getPort());
  25. } catch (UnknownHostException e) {
  26. e.printStackTrace();
  27. Assert.fail("invalid Host Address");
  28. }
  29. return seleniumProxy;
  30. }
Add Comment
Please, Sign In to add comment