Hybrid BrowserMob Scripts

BrowserMob scripts can be written to use VUs (Virtual Users) or RBUs (Real Browser Users); the difference being raw HTML over the wire vs. an Se driven browser. But there are situations where you want to mix the two and create a Hybrid script.

Hybrid scripts have value in…

  • Accessing oracles
  • Environment setup
  • Step shortcutting
  • Advanced synchronization

Hybrid scripts make use of the HttpClient API to sent GET and POST requests along the wire to external resources outside of the Se browser. This script shows just the HttpClient stuff for sending a POST and a GET inside a BrowserMob script. Were it flushed out there would be interaction with the Se browser as well.

var selenium = browserMob.openBrowser();
var httpclient = browserMob.getActiveHttpClient();

var tx = browserMob.beginTransaction();

var getResponse = httpclient.get("http://search.twitter.com/search.json?q=monkey");
var info = getResponse.getInfo();
if (info.getStatusCode() == 200) {
  var responseAsJSON = getResponse.getBody();
  var responseAsObject = eval('(' + responseAsJSON + ')');

var postResponse = httpclient.post("http://adam.goucher.ca/cgi-bin/simple-echo.pl?firstname=adam");
info = getResponse.getInfo();
if (info.getStatusCode() != 200) {
  browserMob.log("POST failed");


When doing load testing through something like BrowserMob, it is generally a better idea to construct your runs in such a manner to not need excessive use of this technique. But should you need it, it is available.

Trackbacks & Pingbacks 1

  1. From A Smattering of Selenium #26 « Official Selenium Blog on 05 Sep 2010 at 4:16 am

    […] to interact with a web service during a BrowserMob run? Hybrid BrowserMob Scripts explains how to do […]

Post a Comment

Your email is never published nor shared. Required fields are marked *