1

I'm currently trying to setup Selenium WebDriver with BrowserMob, to capture network requests in a test. At the moment my setup is as follows:

Development Machine running TomCat on 192.168.1.97, port 8080

On the webdriver:

System.out.println( options.getCapability(CapabilityType.PROXY  ) );

returns:

Proxy(manual, http=192.168.0.97:64181, ssl=192.168.0.97:64181)

We have no corporate Proxy in use on our network.

the following is the code in my test:

@BeforeClass
public static void setupWebDriver() throws MalformedURLException
{
   DesiredCapabilities capabilities = new DesiredCapabilities();
   proxy = new BrowserMobProxyServer();

   proxy.setMitmManager( ImpersonatingMitmManager.builder().trustAllServers( true ).build() );
   proxy.setChainedProxy( new InetSocketAddress( "192.168.1.97", 8080 ) );
   proxy.setTrustAllServers( true );
   proxy.start( 0 );

   // get the Selenium proxy object
   Proxy seleniumProxy = ClientUtil.createSeleniumProxy( proxy );
   seleniumProxy.setSslProxy( "192.168.1.97:" + proxy.getPort() );


   capabilities.setAcceptInsecureCerts( true );
   capabilities.setCapability( CapabilityType.ACCEPT_SSL_CERTS, true );
   capabilities.setCapability( CapabilityType.PROXY, seleniumProxy );

   proxy.setHarCaptureTypes( CaptureType.REQUEST_CONTENT, CaptureType.REQUEST_HEADERS );
   SeleniumHelper.startup( capabilities );
}

What is happening at the minute, is that Chrome is being spawned successfully, and when I have passed the capabilities through to the web driver, the local web server is returning 404 errors for lots of the requests. These all seem to be external resources (as opposed to requests coming directly from TomCat) so I'm pretty close in my solution, just can't get BrowserMob to connect to third-party HTTP and HTTPS resources. e.g. jQuery fails, Google Analytics fails, etc. etc.

I've checked HAR resources in an actual resource and the proxy does seem to get hit, as I'm able to read HAR resources. ie. I get output from this:

super.getProxy().newHar("check.har");

goTo( "/507393" );
waitForNavigation();
Har har = super.getHar();
HarLog log = har.getLog();
List<HarEntry> entries = log.getEntries();
for(HarEntry entry: entries ) {
    HarRequest request= entry.getRequest();
    System.out.println( request.getUrl() );
}

If I remove the lines for Chained Proxy, Selenium doesn't connect to any web server at all. Whether a chained proxy is needed for a local setup I suspect not, but I'm getting further with it than without it at this point.

Can anyone see anything wrong? I'm assuming because I'm running "embedded" mode I don't need to run the proxy at the command line?

Are there any additional settings worth exploring?

Squiggs.
  • 3,037
  • 6
  • 40
  • 73

0 Answers0