The BrowserMob Blog | All about browsers, performance testing, and load testing

Dec/09

3

The BrowserMob equivalent of a “hosts file”

We get this question a lot: “Is there any way to change the hosts files on the machines that your browsers run from?” – or something similar.

The reason is always because there is a desire to monitor or test a site that doesn’t yet have the final DNS mappings put in place (ie: dev, staging, etc) and the development process has up until now worked by having team members edit their “hosts file”, a small DNS override that Windows, Mac OS X, and Linux all support.

This hosts file might look like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1           localhost
255.255.255.255     broadcasthost
::1                 localhost 
fe80::1%lo0         localhost
 
123.456.789.123     example.com

In here are defaults that the OS configures. This is where “localhost” is actually mapped to your local IP address: 127.0.0.1. And also in this example, the domain example.com is mapped to a fictitious IP address.

While BrowserMob doesn’t allow you to override the hosts file, it does let you accomplish the same goal of remapping a domain/host to a different IP than what is in the public DNS records. All you have to use is the HttpClient’s remapHost API.

This works for Virtual User scripts:

var c = browserMob.openHttpClient();
c.remapHost("example.com", "123.456.789.123");
...

As well as for Real Browser User scripts:

var selenium = browserMob.openBrowser();
var c = browserMob.getActiveHttpClient();
c.remapHost("example.com", "staging.example.com");
...

As you can also see in these examples, you can map to another host or an IP address.

[Post to Twitter] Tweet This Post 

No tags

No comments yet.

Leave a Reply

<< Announcing dynaTrace AJAX Edition: a first-class IE browser profiler

Cyber Monday final results: Amazon the big winner; Borders and Kohl’s stumble >>

Theme Design by devolux.nh2.me

Tweet This Post links powered by Tweet This v1.3.9, a WordPress plugin for Twitter.