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

How to Perform a Loop Inside a Test

Some people have asked us if it is possible to have a user repeat a number of actions after they have logged in or created an account.

Below is a sample RBU script that does just that. The same idea can apply for VU scripts too.

Please keep in mind that the loop should be “contained” and ideally set to a minimum loop count during validation – otherwise you’ll be waiting a long time for the script to validate!

var selenium = browserMob.openBrowser();
 
// Change this to whatever makes sense for the load test
var loops = 10;
if (browserMob.isValidation()) {
    loops = 2; // no need to loop so many times if we're validating!
}
 
// now login here - things done here will not be part of the reported transactions...
selenium.open("http://example.com/login");
selenium.type("username", "patrick");
selenium.type("password", "password");
selenium.clickAndWait("login");
 
// now start the loop which will run the "real" transaction multiple times against the same browser session.
 
for (var i = 0; i < loops; i++) {
    browserMob.beginTransaction();
 
    browserMob.beginStep("Home page");
    selenium.open("http://example.com/home");
    browserMob.endStep();
 
    // more steps and browser actions here...
    browserMob.endTransaction();
}

[Post to Twitter] Tweet This Post 

No comments yet.

Leave a Reply

Theme Design by devolux.nh2.me

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