Tweaking BrowserMob-Proxy

Posted by Stuart Herbert on August 10th, 2012 in Toolbox.

If you’re writing tests for your web-based applications (and if you’re not, I’m sure Chris Hartjes will want a stern word with you …), then you might be using a combination of Selenium 2 / aka Selenium WebDriver and WebMetrics’ BrowserMob-Proxy for your testing.

WebDriver is the latest Selenium API for controlling real web browsers such as Internet Explorer, Firefox and Chrome, and BrowserMob-Proxy adds in essential missing capabilities such as checking HTTP status codes and injecting headers for HTTP Basic Auth.

I’ve recently forked BrowserMob-Proxy on GitHub and started to make tweaks to it for work. Thought I’d mention it, in case anyone else out there is using BrowserMob-Proxy and would find our tweaks useful too. We’ll be submitting our tweaks upstream in due course.

  • Executable JAR – Maven POM file updated to build browsermob-proxy-X.XX-standalone.jar – an executable JAR file – during the ‘package’ phase. Very handy if you’re running and testing it via the remote API. Upstream’s browsermob-proxy-X.XX-bin.zip is still available, and is now always built during the ‘install’ phase.
  • /features endpoint – a new REST API endpoint allowing you to GET and POST and DELETE feature flag settings. We’re using this to enable/disable any new features that might break backwards compatibility, in case you want to use existing BrowserMob-Proxy REST clients with our tweaked version. Said REST clients can also use this to see which features are present / enabled.
  • enhancedReplies – by default, BrowserMob-Proxy isn’t the most chatty of REST services. Switch this feature on (POST ‘enhancedReplies=true’ to /config/enhancedReplies), and now every response includes either a ‘success: TRUE’ or an ‘error: TRUE’ field for your client to easily understand what has happened.
  • More logging – we’ve added some additional log messages throughout the ProxyResource REST API, to make it easier to debug browsermob-proxy REST API clients. This logging is off by default, and is switched on by POSTing ‘paramLogs=true’ to /config/paramLogs, and/or POSTING ‘actionLogs=true’ to /config/actionLogs.
  • additional header GET / DELETE API – we’ve extended the REST API for additional HTTP request headers to now allow you to GET /proxy/:port/header/:name and to DELETE /proxy/:port/header/:name if you need to. You can also delete all additional HTTP request headers in one go by DELETE /proxy/:port/headers.
  • REST API for HTTP Basic Auth – BrowserMob-Proxy’s existing support for HTTP Basic Auth is now available via PUT /proxy/:port/basicAuth/:domain. One of the key features missing from WebDriver. (This is a convenience feature; it could be done by injecting the headers directly into BrowserMob-Proxy).
  • exception handling – by default, BrowserMob-Proxy lets exceptions bubble up to the servlet container … which unfortunately sends back HTML errors rather than a JSON error. To make things a little easier for REST clients, I’ve tweaked the REST API to trap exceptions and return back a (hopefully suitable) error class. This will probably need more tweaking before it provides useful information all the time.

Bookmark this page; I’ll be updating it as we complete more tweaks to BrowserMob-Proxy.

Comments are closed.