We recently wrote a post about how to randomize an IP address and tie it to the domain name for RBU scripts. Here is how it is done for VU scripts.
var ips = ['169.125.57.119', '169.230.103.88', '169.125.17.0', '169.125.17.68', '79.125.17.80', '169.125.38.66', '169.125.43.112'];
var ip = ips[Math.floor(Math.random() * ips.length)];
browserMob.log("Using ip " + ip);
var c = browserMob.openHttpClient()// useful function that rewrites the hosts and auto checks the response code
var get = function(url) {
var rewrittenHost = null;
if (url.indexOf('http://www.aktiesport.nl/') == 0) {
rewrittenHost = 'www.aktiesport.nl';
url = 'http://' + ip + '/' + url.substring('http://www.aktiesport.nl/'.length);
}
// create the request
var req = c.newGet(url);
// Leave validation text blank. This let us avoid specific validation
// but still get BrowserMob to capture the content if there is an error
req.setVerificationText('');
if (rewrittenHost != null) {
req.addRequestHeader("Host", rewrittenHost);
}
// make the request
var resp = req.execute();
// and check the response code
var code = resp.getInfo().getStatusCode();
if (code != 200) {
throw "Expected 200 but got " + code;
}
}
browserMob.beginTransaction()
You can now write the rest of the script as normal simply using mysite.com and ignoring any IP address issues. This is quite useful for running tests when your loadbalancer isn’t in place yet.




Recent Comments