Functional testing over a proxy with BrowserMob Proxy

Last week we experienced a little outage on our websites (We have website with a lot dependencies with external system and third-party content). It gave us the opportunity to take a closer look at our products while having production issue. One thing we noticed is that we don”t tell the end-user that we are having issues. We have learned that we have to built-in a more resilient user experience during issues.

We can simulate these kind of failures while testing over a proxy. BrowserMob Proxy can be controlled by a REST interface and has some great capabilities, such as blacklisting and whitelisting certain URL patterns, simulating various bandwidth and latency and controlling DNS and request timeouts.

As I said, BrowserMob Proxy is a REST tool. In order to perform REST calls we have to install cURL.

Windows

  • Download cURL from http://curl.haxx.se/
  • Extract the compressed file
  • Put curl.exe in c:/Windows/ (to enable curl from the command prompt)

Linux

  • sudo apt-get install curl

Or some other installation command which is related to the Linux distribution.

Starting the proxy

In the first command prompt

  • navigate to the bin directory
  • Start the proxy by entering
    browsermob-proxy.bat -port 9090

    or the Linux equivalent

    ./browsermob-proxy -port 9090

In the second command prompt

  • Perform the following curl command to create a new proxy,
    curl -X POST http://localhost:9090/proxy
  • This will return a new proxy port, something like: {“port”:9091}
  • You can create a new HAR to start recording data, like this:
    curl -X PUT -d ''initialPageRef=newHar'' http://localhost:9090/proxy/9091/har

InternetOptions-423x288

Set the proxy in browser

  • Navigate to Control Panel -> Internet Options * Goto LAN settings in the Connections tab
  • Thick Use a proxy server for you LAN
  • Fill in the address: localhost
  • Fill in the port: 9091 (the one returned from the curl command)
  • Click on OK twice

Limit the connection speed
Perform the following curl command in the command prompt:

curl -X PUT -d "downstreamKbps=50" http://localhost:9090/proxy/9091/limit

Now you can visit the website with a low connection speed.

Blacklist third-party content

Perform the following curl command in the command prompt:

curl -X PUT -d "regex=http://example.com/*.*&status=404" http://localhost:9090/proxy/9091/blacklist

Now you can visit the website while blacklisting some content.

Reference
Check the BrowserMob Proxy readme (on Github) for all available API commands.

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *