Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- browserMobProxy = getProxyServer(username, password);
- Proxy seleniumProxy = getSeleniumProxy(browserMobProxy);
- System.setProperty("webdriver.chrome.driver","P:/AppDev/MIS Projects/Selenium/chromedriver.exe");
- ChromeOptions chromeOptions = new ChromeOptions();
- chromeOptions.addArguments("user-data-dir=" + profileLocation);
- chromeOptions.addArguments("disable-infobars");
- chromeOptions.setCapability(CapabilityType.PROXY, seleniumProxy);
- private static BrowserMobProxy getProxyServer(String username, String password) {
- BrowserMobProxy proxy = new BrowserMobProxyServer();
- proxy.setTrustAllServers(true);
- proxy.start();
- String credentials = username + ":" + password;
- String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString(credentials.getBytes()));
- proxy.addHeader("Authorization", encodedCreadentials);
- return proxy;
- }
- public static Proxy getSeleniumProxy(BrowserMobProxy proxyServer) {
- Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyServer);
- try {
- String hostIp = Inet4Address.getLocalHost().getHostAddress();
- seleniumProxy.setHttpProxy(hostIp + ":" + proxyServer.getPort());
- seleniumProxy.setSslProxy(hostIp + ":" + proxyServer.getPort());
- } catch (UnknownHostException e) {
- e.printStackTrace();
- Assert.fail("invalid Host Address");
- }
- return seleniumProxy;
- }
Add Comment
Please, Sign In to add comment