Hi All,
In my current project, we have a requirement to add User-Agent while running a UI automation script.
I have implemented it via browsermobProxy. Below is my code for creating the proxy instance.
private Proxy getProxy(){
logger.info("Starting the browsermob proxy server!");
//start the proxy
proxy = new BrowserMobProxyServer();
proxy.start();
proxy.addRequestFilter(new RequestFilter() {
@Override
public HttpResponse filterRequest(HttpRequest httpRequest, HttpMessageContents httpMessageContents, HttpMessageInfo httpMessageInfo) {
httpRequest.headers().remove("User-Agent");
httpRequest.headers().add("Value");
logger.info("Url to be intercepted :: "+httpMessageInfo.getUrl());
return null;
}
});
//get the Selenium proxy obj
logger.info("Proxy created at :: "+proxy.getPort());
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
seleniumProxy.setHttpProxy("localhost:"+ proxy.getPort());
seleniumProxy.setSslProxy("localhost:"+ proxy.getPort());
seleniumProxy.setFtpProxy("localhost:"+ proxy.getPort());
seleniumProxy.setProxyType(Proxy.ProxyType.MANUAL);
return seleniumProxy;
}
and below is the code to create the desired capabilities for the browserstack.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserstack.user", "user");
caps.setCapability("browserstack.key", "key");
caps.setCapability("browserstack.console", "errors");
caps.setCapability("browserstack.local", "false");
caps.setCapability("browserstack.timezone", "IST");
caps.setCapability("browserstack.localIdentifier", browserStackProperties.getSessionId());
caps.setCapability("acceptSslCerts", "true");
caps.setCapability(CapabilityType.TAKES_SCREENSHOT, "true");
caps.setCapability("browserstack.video", "false");
caps.setCapability(CapabilityType.VERSION, "86");
caps.setCapability(CapabilityType.PROXY, getProxy());
And there are other connection methods to the browserstack and the chromoptions settings code.
But I am getting "No Internet" while I execute the scenarios either locally or on jenkins.
The above scenario fails with the high level error : org.openqa.selenium.WebDriverException: unknown error net::ERR_PROXY_CONNECTION_FAILED.
Any clues or suggestions would be appreciable.