WatirGrid 1.0.6 released … can haz Selenium?

I’ve just released WatirGrid 1.0.6 which now includes support for Selenium WebDriver… So can I really call it WatirGrid anymore? Realistically the Watir and Selenium projects are headed in the same direction courtesy of WebDriver, so it makes sense to give Watir users (I like to think of them as Ruby users ;)) the option to use Selenium where it best fits.

Continue Reading

About these ads

Watir Day and Selenium Conference .. w00t


What an awesome experience. Despite spending most of it jet-lagged, travelling to San Francisco was such a great experience for me, and helped reaffirm just how strong the Watir and Selenium community is. Without dropping names, some of the experiences I got to enjoy were:

  1. Sharing late night beers and early morning burgers with the leader of Watir development
  2. Pair coding on watir-webdriver performance extensions with the smartest kid in Norway
  3. Finally meeting perhaps the leader of Australian based Watir testing
  4. Eating chinese with the god-father of Watir and hearing some great anecdotes on the origins of Selenium
  5. Shown the light on page objects, opera and superbad with a Polish born American
  6. Hearing about the inner workings of ‘that other browser’ from a genius at Opera
  7. Learning more about the Watir community and getting a thirst for Croatian micro breweries
  8. Meeting my role model in person and perhaps feeling a bit shied by his awesomeness!
  9. Getting some great advice and tips for my own startup
  10. Being awed and perhaps jealous (in a slightly convict vs. colonial way) of the greatest mind behind webdriver

I met many other people whilst there, did tons of late night coding and got to experience public speaking for the first time. A big thank you to all the organisers of #watirday and #seconf. Looking forward to the next!

Regex in BrowserMob Scripts

If you’re using an RBU or VU you may need to extract content from the previous response. For example, enumerate a link to a PDF file for subsequent download.

The BrowserMob interface has a handy findRegexMatches method you can call as follows:

var link = browserMob.findRegexMatches(selenium.getHtmlSource(), 'href="(.+?pdf)"');
  browser.get(link[0], 200);

It takes a string input and regex pattern parameters. For the string input I am simply passing in the HTML source from the previous request based on a browser object:
var browser = browserMob.getActiveHttpClient();

The regex pattern is self explanatory. The link object will be an array of matches; in this case I’m issuing a get request for the first link in the match array. You might want to add some more code to make this more robust e.g. if no links are found etc.

Pretty simple hey!

Emulating Think Time and Pacing with BrowserMob

If you come from the commercial toolset mindset, you might be interested in how we achieve think time and pacing when using alternatives such as BrowserMob.

Think Time
Think time, is normally defined as the amount of time a virtual user ‘thinks’ between individual steps within a transaction. This time is usually excluded from response time measurements and is an important inclusion in terms of script behaviour. Having no think time means the virtual user will race through transactions more quickly than a normal user would which potentially creates unrealistic load. So how do we emulate think time behaviour in a BrowserMob script?

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.

The BrowserMob interface (API documentation here) has a pause method as follows:

This effectively pauses the user for a period of 15 seconds in the previous example.

The Selenium interface (API documentation here) also has a similar setSpeed method which will set the number of milliseconds to pause after each step elminating the need to specify individual pause statements between each step as follows:

If you would like to emulate some common think time settings as you might see in a LoadRunner script you can implement the following at the top of your RBU or VU scripts:

// Multiply think time by:
var think_time_multiple = 1;

// Use random percentage for think time e.g. 50 - 100:
var think_time_percentage = 50 + (Math.random() * 100);

// Limit think time to:
var think_time_limit = 0;

// Set think time to:
var think_time = 3; //seconds

if(think_time_limit > 0) {
  selenium.setSpeed(think_time_limit * 1000);
} else {
  selenium.setSpeed(think_time * think_time_multiple * (think_time_percentage/100) * 1000);

If you need additional think time after steps then you can add the following statement where required:
browserMob.pause(3000 * think_time_multiple * (think_time_percentage/100));

Some people like to control transaction volume/throughput by messing about with think time. I don’t favour this approach because you need to first be cognisant of how long each iteration will take including think time then adjust think time accordingly. Once it’s set (or hardcoded into your script) then the vusers are stuck with that setting. I much prefer the pacing concept, which determines how long a vuser should ‘wait’ before starting the next iteration. This wait time is determined by elapsed time including any server side processing, not just user think time. So how do we emulate pacing in a BrowserMob script?

First I like to set some targets such as the transaction rate (per hour per user) and then calculate the pacing from this target. I also set a variable iterate to true, which comes into play in the main body of the script.

// Run logic
var transaction_rate = 10;  // Target transaction rate per hour per user
var pacing  = 60*60*1000 / transaction_rate;
var iterate = true;

Now we’ve got the target and pacing set, we can get into the main logic. Let’s start an iteration.

while (iterate) {
  var start = new Date();

Notice I’ve used a while loop which checks for the iterate boolean and creates a start date time stamp. I also initiate a BrowserMob transaction.

After we complete the iteration (which is essentially a bunch of BrowserMob steps) we can close the while loop with some pacing logic.

  // Calculate Pacing
  var finish  = new Date();
  var elapsed = finish.getTime() - start.getTime();

  if (browserMob.isValidation()) {
    browserMob.log("Adjusted pacing would be "+ (pacing - elapsed) + " msecs");
    browserMob.log("or " + Math.round(3600000 / (pacing - elapsed) ) + " trans/hour");
    iterate = false;
  } else {
    if(pacing > elapsed)
      browserMob.pause(pacing - elapsed);


This will calculate the finish date time stamp and then determine the difference between the previously calculated target pacing and the actual time elapsed. If there is a difference then the user will pause, otherwise it will just continue on to the next iteration. This basically allows you to target a set number of transactions per hour. When validating the script it will output these calculations to the log file.

Instant Website Tests with BrowserMob

Can you afford a slow landing page?

Google AdWords page quality criteria are many, a prominent check being your landing page load time. A slow load time can lead to a lower quality score.

Make sure you’re not wasting effort on advertising campaigns. Altentee uses BrowserMob to help check website performance for clients from multiple locations. You can run a free check using the form below.

(redirects to BrowserMob)
If you need help optimizing your landing page, or help with performance testing in general feel free to contact Altentee today.

Using Selenium RC to automate your web based testing

Selenium is an awesome free alternative to apps such as Quick Test Pro and the like, providing you with a browser based automation suite for web applications.

Selenium uses JavaScript and Iframes to embed a test automation engine in your browser. This technique should work with any JavaScript-enabled browser. Selenium Remote Control provides a Selenium Server, which can automatically start/stop/control any supported browser. It works by using Selenium Core, a pure-HTML+JS library that performs automated tasks in JavaScript.

In this demo, I’ve used Selenium-RC and Perl to automate the checking of a promotional website called FreeStuffDay where every month you can have the chance to secure an advertised item for free. Instead of me sitting behind a browser checking the availability of free items manually, I’ve written a quick demo script to show you how it’s done from Perl and Selenium-RC.
Continue Reading