I am able to modify http request header using BrowserMobProxy, the same way explained
https://sqa.stackexchange.com/a/37318/9043
But, the problem I am having at the moment is, that I am executing my scenarios on dev/local/playpen environment (environment before System integration testing). And to open the website on this environment needs proxy to set.
When I set my proxy then it fails to modify header and apply the proxy. When I comment the proxy part then it easily modifies the header.
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
proxy.addRequestFilter((request, contents, messageInfo)->{
request.headers().add(“some-header-attribute”, “RandomeValue”);
System.out.println(request.headers().entries().toString());
return null;
});
String _host = Utils.getConfigValue(“proxy.host”);
String _port = Utils.getConfigValue(“proxy.port”);
seleniumProxy.setProxyType(Proxy.ProxyType.MANUAL);
seleniumProxy.setHttpProxy(_host + “:” + _port);
seleniumProxy.setSslProxy(_host + “:” + _port);
seleniumProxy.setFtpProxy(_host + “:” + _port);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
String proxyOption = “–proxy-server=” + seleniumProxy.getHttpProxy();
options.addArguments(proxyOption);
Source: Read More