Introducing User Think Time

BrowserMob supports simulating “user think time” by allowing you to control the speed in which browser interactions occur, as well as script in manual pauses. Depending on the application you are testing and the goals of your test, “user think time” may be an important part of your script.

For example, consider a normal browser script that goes to a page, fills out a form, and then clicks on several links:

var selenium = browserMob.openBrowser();
 
browserMob.beginTransaction();
 
browserMob.beginStep("Step 1");
selenium.open("http://example.com/login");
selenium.type("username", "joe");
selenium.type("password", "password");
selenium.clickAndWait("loginBtn");
browserMob.endStep();
 
browserMob.beginStep("Step 2");
selenium.clickAndWait("link=Foo");
browserMob.endStep();
 
browserMob.beginStep("Step 3");
selenium.clickAndWait("link=Bar");
browserMob.endStep();
 
browserMob.endTransaction();

This script would fill out the login form, click the login button, and then click two additional links as fast as it possibly can – much faster than a real human would.

This may be exactly what you want. It does, after all, ensure that your script packs in as much activity against your website as possible per dedicated Real Browser User (RBU) or Virtual User (VU) participating in the test.

But sometimes your tests need to be more realistic. For example, you might wish to measure the true capacity of the site, taking in to consideration all the server-side sessions and the impact they have on CPU and memory even when active HTTP requests are not being made from the browser. Or your web app might involve advanced AJAX techniques that actually cause additional HTTP activity even when the user is sitting idle (ie: a live chat website).

BrowserMob supports this type of think time with two important commands:

  • browserMob.pause()
  • selenium.setSpeed()

The browserMob.pause() command can be used by both RBU and VU scripts and does exactly what you would imagine it would do: it causes the script to pause for the specified amount of time (in milliseconds). So if, for example, we wanted to pause for exactly 15 seconds after logging in in the previous script, we would have:

var selenium = browserMob.openBrowser();
 
browserMob.beginTransaction();
 
browserMob.beginStep("Step 1");
selenium.open("http://example.com/login");
selenium.type("username", "joe");
selenium.type("password", "password");
selenium.clickAndWait("loginBtn");
browserMob.endStep();
 
// pause for 15 seconds
browserMob.pause(15000);
 
browserMob.beginStep("Step 2");
selenium.clickAndWait("link=Foo");
browserMob.endStep();
 
browserMob.beginStep("Step 3");
selenium.clickAndWait("link=Bar");
browserMob.endStep();
 
browserMob.endTransaction();

The selenium.setSpeed() command may only be used by RBU scripts. This command causes an automatic pause of the specific amount of time (in milliseconds) after any other selenium function call. This means each action taken against the browser (ie: type, click, drag, etc) will wait an additional X milliseconds before returning. So if, for example, we wanted to simulate how a real user would act by waiting 2 seconds between each action, we would have:

var selenium = browserMob.openBrowser();
 
// wait 2 seconds after each browser command
selenium.setSpeed(2000);
 
browserMob.beginTransaction();
 
browserMob.beginStep("Step 1");
selenium.open("http://example.com/login");
selenium.type("username", "joe");
selenium.type("password", "password");
selenium.clickAndWait("loginBtn");
browserMob.endStep();
 
browserMob.beginStep("Step 2");
selenium.clickAndWait("link=Foo");
browserMob.endStep();
 
browserMob.beginStep("Step 3");
selenium.clickAndWait("link=Bar");
browserMob.endStep();
 
browserMob.endTransaction();

Note that in this last example, because we wanted 2 seconds between each command, the total time spend paused is 12 seconds because there are 6 browser commands.

It is also important to note that the time spent paused is broken out from the normal timing of the transaction and the step. This allows you to still focus on the raw performance of the user-initiated requests (ie: clicking a link, typing text, etc) while still keeping track of the pause time. Please consult the ad-hoc SQL documentation for more information on the time_active and time_paused columns.


One Response to “Introducing User Think Time”

  1. [...] The BrowserMob replay engine drives Selenium scripts, so you will need to play in the JavaScript sandbox so to speak, in order to emulate think time. There’s some well documented ways to implement this on the BrowserMob blog here. [...]

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

 

© 2012 The BrowserMob Blog Suffusion theme by Sayontan Sinha