After reading Boris Kozorovitzky’s blog article, “How to use JavaScript in your HP LoadRunner scripts”, I’ve been inspired to experiment with LoadRunner 12.
Historically, most LoadRunner functions have been written in C but many performance testers (me included) aren’t particularly fond of C and prefer to use more up to date languages. I was already aware that there are some great JavaScript libraries out there which can extend the functionality of LoadRunner, but I hadn’t tried them until now.
Boris’ article describes how to integrate JavaScript code into your C-based scripts. Following his guidance I developed a script which uses the DateJS function for date calculations. I’m impressed with the flexibility of DateJS and the extra capabilities that it offers over the standard LoadRunner date/time functions.
To incorporate the DateJS functionality into my script I did the following:
- Turned on the “Enable running JavaScript code” function.
Run-Time Settings > Internet Protocol > Preferences > Set advanced options > Options - Added my date.js code into the script using Solution Explorer.
Right-click “Extra Files”node in Solution Explorer
then choosing the option to “Add files to script” - Adding JS functions to the script is then achieved by using the LoadRunner web_js_run function.
e.g.
I added my sample script to my GitHub repository so that other people can see just how easy this is and potentially benefit from the new date/time functions in this sample LoadRunner script.
You can download the script here: https://github.com/richardbishop/LoadRunnerSamples/tree/master/DateJS