Extending Loadrunner Scripts with C – Function Library #1.1

Actually, this is more like 1.1. In as much as it ties into the previous post. I was blogging about building audit logs and data files via an “audit” script. That’s what I call them, not sure if there’s a full blown technical name but I use them to verify, validate and build data to be used in actual test scripts.
So let’s suppose you have an array of data you’ve captured with web_reg_save_param (x,y,z,"ord=all",last); this is how to handle that code into an audit log.


// write file header once


return 0;
The function as defined in the previous post.
int WriteToOutputFile(char * string)

char *filename = “c:\\gemalto_audit.txt”;
long file_streamer;

if ((file_streamer = fopen(filename, “a+”)) == NULL)
//open file in append mode
lr_error_message (“Cannot open %s”, filename);
return -1;

fprintf (file_streamer, “%s\n”, string);
return 0;

And finally, the function in use…

char szParamName1[128];
char szParamName2[128];
char szParamName3[128];
// get number of matches from ord=all

nCount = atoi(lr_eval_string("{available_cards_psn_count}"));

//"available_cards_count" = 22 - boundaries are insufficiently unique
//"available_cards_psn_count" = 11
//"available_cards_status_count" = 22 - boundaries are insufficiently unique

for (i=1; i<=nCount; i++ )
j = i * 2;
sprintf(szParamName1, "{available_cards_%d}", j);
sprintf(szParamName2, "{available_cards_psn_%d}", i);
sprintf(szParamName3, "{available_cards_status_%d}", j);

I find more often than anything else, capturing the data is easy enough, but getting at that data in a structured way in order to use it effectively at a later point can be painful. The above is a real-life example – Developers implementing the content management inconsistently meant that there was nothing uniquely identifying 2 of the fields I needed. If I tightened the left boundary or the right boundary, elements were missed.
I’m not criticizing developers per se, they can’t really be expected to think about a performance tester a year down the life-cycle of the project looking at source-code structure.
The workable solution was to capture the 11 values I needed for one element, the 22 value-pairs for the other elements, and just skip every other element in 2 of the arrays. Inelegant perhaps, it works though and I built that today so it may become beatified over time.

And then there were 2…

I’ve just been asked by my boss to build a proof of concept for a scheduling system, not to execute performance tests but to book time slots on the shared controller.
It’s not unusual that a controller would be shared by a number of testers, very few projects require and use 24.7 access to Loadrunner, most scripting is done on an independent machine (VUGen can be installed and run independantly of the Controller) and there are often multiple workstreams.

Now I’ve worked in a million different places, and I’ve seen some booking solutions over the years and it is my opinion that most automated testers can’t be doing with them, they’re clunky, slow to complete and just another layer of irritating bureacracy. Mine will no doubt be the same.

Looking at 2 possibilities off the top of my head:
1. Spreadsheet on a shared drive. This has the advantage of being simple to build, but sharing requires opening and closing the document to prevent locking, and there’s usually one hog in my experience.
2. Online booking system with a php-based calendar and a webform tied into a mysql database at the back-end. I can build that with resources acquired on the net and customise to fit but it will still take longer than the spreadsheet.

As a POC-request, I’ll end up doing both and asking the testers which they prefer, and the answer will almost certainly be “Neither, can’t we just get together and figure out who needs it when they need it.”
Yes, yes we can. Over a beer?

New Development Project – Loadrunner Scheduler

Amongst all the other tasks I have with performance testing and automating on client sites, and sleeping, I once developed an excel-based scheduler for Loadrunner.

IT doesn’t rain but it pours…

Further to my last post, on the vague subject of a test run database and results repository. There are, of course, additional features to add to that. Especially if you wanted to provide it to clients at a cost.

It would need to be able to cross-match results on the fly, comparing like-for-like transactions/scripts/scenarios.

I’m not proposing to re-develop the analysis tool for loadrunner, that’s outside my scope at the moment (probably 😉 )
But something comparing Run A vs Run B of the same test in pure numerical terms sounds like a job for perl to me.
And yeah, maybe have it draw a graph, pretty sure that’s do-able on the fly.

So Working, Building and Researching. What’s new?

So what have you been doing?

It’s been a long time since I had the time and inclination to update the site. Partly because I’ve been busy working and partly because I was hideously aware that the next stage for the site was complicated and not exactly in my wheelhouse. I can code, clearly, since I automate everything and work as an automation expert internationally. But I’m not a business analyst, a technical architect, a data analyst or a developer. Not really, at least.

Extending Loadrunner Scripts with C – Function Library

So, I’m working at a new client, back doing the Loadrunner thing. One of the nice things about that is I get to re-use and refine code I’ve written previously for other clients. This article is going to contain some of these code snippets that I’ve used time and time again.

I’ve re-visited this code recently and found that a) it wasn’t very good, and b) I can do it better now – presented below is the better version. There will be an update inviting formatting etc.
And there’s no guarantee this is perfect.

Output to Text file

int WriteToOutputFile(char * string)

char *filename = "c:\\myfilename.txt";
long file_streamer;

if ((file_streamer = fopen(filename, "a+")) == NULL)
//open file in append mode
lr_error_message ("Cannot open %s", filename);
return -1;

fprintf (file_streamer, "%s\n", string);
return 0;

Called like this:

WriteToOutputFile(lr_eval_string("bban_count: {bbanNumber_count} blah {bbanNumber_count}"));

I just added the function beneath vuser_init rather than creating a header file. For multiple vusers, it’s a good idea to parameterise the filename as they can’t all share. I recommend a vuser identification parameter as thats built in.
Or Timestamps for uniqueness.

I also have a dos script for joining them all back up again since I tend to use this function for creating custom audit logs to track test data states as it moves through a scenario / test cycle.

A failed web_find is not always an error

I’ve been working in Lithuania for the last 3 months. It’s cold over here. To keep warm (and paid), I’ve been writing some loadrunner scripts for a Scandinavian bank. One of them seeks to emulate a customer paying cash into their account. As you’d imagine, this is a high priority, high usage script so I’ve spent the last 3 weeks building this in the web protocol against a custom built CRM platform.

First Steps with WATIR

Watir is an open-source ruby-based browser automation tool. I first looked at it 6 months ago but with a new loadrunner role to involve myself with, I didn’t get far.

In any case, these are the steps I took to get started and to get things up and running.

  • 1. Install Ruby from ruby-lang.org. I chose version 1.9.2 as the most current stable build (despite a warning stating that Watir didn’t work on 1.9.2… we’ll see about that).
  • 2. Following the instructions here on watir.com, I updated the rubygems and installed Watir. I left the firefox addin as it’s not compatible with the latest version and I was loathe to downgrade my main browser. I have IE and Chrome too so I figured if one of them would run, that would be sufficient.
  • 3. Picked up the watir-webdriver whilst I was at it. Documentation can be found here at the excellent watirMelon site. I just used this command in a dos prompt:

    gem install watir-webdriver

  • 4. I grabbed the chromedriver executable from here and dropped the executable in my ruby/bin/ folder as I know that’s in my path.
  • Automated Testing Best Practices (Basic)

    I wanted to prepare an article that specifies the very basic best practices for Automated Testing, whether its functional or non-functional. It seems to me that all the tools, whether open-source or commercial allow for these essential practices, presumably because this is the way we should all be doing it… some of us aren’t, you know who you are and you’re very naughty. Also your testing isn’t as good as it should be…

    This article is very much a work-in-progress as I braindump…

    1. All scripts should have a manual equivalent, because this is the foundation upon which the automation is built. It doesn’t have to be complicated, it doesn’t have to be as thorough as the automated script, but it does have to accurately specify the steps to follow.
    2. Some of the tools are best used in a record-edit-playback loop (Loadrunner for example). Others pretty much require you to edit them as you progress through your script, adding checkpoints and things as you go (QTP springs to mind). If its a pain to go and insert checks after the recording, that is just tough. Your test is only as good as the conditions it checks for.
    3. A good understanding of the tool is required before you begin any testing phase. Yes, we all have to start somewhere, and that somewhere should always be with training additional reading.
    4. All scripts have transactions, whether its a page click, a text entry, a mouseclick, whatever. Defining your test by these transactions makes debugging easier, makes the scripts more readable and ultimately makes you look professional. Alternatively, a multi-step business process should be mapped as a single logical transaction.
    5. All scripts should include checkpoints for every “transaction” regardless of whether there’s a condition defined. Again its not complicated but your checkpoints need to be sufficient that if something is broken AT ANY POINT your test can detect it.
      If you check for something unique to where you are in the AUT and set pass/fail criteria around that, that’s perfect. The sooner a test which has failed is known to have failed is the sooner the processor is moving on the next activity, saving time and money. And the sooner you’ll be debugging which is one of the fun bits in my opinion

    First Steps with QTP part 2

    Ok, in place of the planned article on QTP automation which I promise I will get to eventually, this post will be about interacting with files through QTP.

    Typically we’ll want to handle text files (for error logging and general message transmission) or Excel files. To begin with though, there are some standard declarations required.

    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim fso, f

    Powered by WordPress and ThemeMag