I have been thinking of creating my own blog on loadrunner scripting for a long time now. And finally here I’m in the process of writing up my first post! And not surprisingly it is about the new loadrunner API for scripting HTTP/HTML applications - Click and Script. I was a little skeptical when I was asked to do the scripting for the project that I'm currently working on with C&S. I'll cover the reasons that fueled this thought in my subsequent posts.
After working on this protocol for the past half 'n year or so, I now feel confident that C&S could be the future and has the power to phase out the HTTP/HTML protocol. Let us not start an argument on this now but jump directly in and look at one of the powerful features in C&S, regular expressions. Since you are reading this you would have done some kind of scripting in loadrunner already and not to mention you would have on numerous occasions come across dynamic text links such as order numbers, confirmation numbers, reference numbers etc. If you are using the HTTP/HTML protocol, you would normally use the web_reg_save_param() function to capture the dynamic text at run time to use with the subsequent request. This is by far the only way to ensure that the script replays as expected during debug or when run in the controller.
With C&S too you can use the web_reg_save_param() calls and expect the same behavior. But why do this when you have this amazing new feature.
Consider this scenario.
You have a banking application and you have done an online transaction. When the transaction is successfully completed, the system generates a unique confirmation number that is displayed on the web page as a text link. On clicking this link you will be displayed the summary on the transaction. To keep things simple, let us assume that the confirmation number has a fixed format and consists of only digits. Normally to generate a web request to emulate user clicking on the confirmation link, we would use web_reg_save_param() and capture the runtime confirmation number and use the same in the next request which would be an action function either web_url(), web_link(), web_submit_form() or web_submit_data().
With C&S this is unassumingly very easy; you don't even have to use the good old web_reg_save_param(). Here is this snippet that does exactly these using regular expressions.
web_text_link("Confirmation number",
"Snapshot=t9.inf",
DESCRIPTION,
"Text/RE=[0-9][0-9]*[0-9]$",
"Ordinal=1",
ACTION,
"UserAction=Click",
LAST);
Look closely at the Description argument. I have used here "Text/RE=[0-9][0-9]*[0-9]$". This essentially instructs the replay engine to look for a link in the server response that starts with a digit, has one or more following digits<[0-9]*> and ends with a digit <[0-9]$> and click on the first occurrence [ordinal=1] of such a link. Isn’t this easy.
When using the test flag /RE along with the description, the loadrunner replay engine interprets that the description provided is not in its literal sense but as a regular expression. This can be compared with the old text flags like /IC, /DIG, /ALNUMIC etc. that you would have used with web_reg_find() or web_reg_save_param() functions, but far more powerful.
You can get more information on regular expressions from the many textbooks dedicated to the subject and by searching the Internet.
Note that the requirements of load testing rarely require the full power of regular expressions and that sophisticated use of regular expressions make a Vuser script harder to understand and debug. Moreover, use of REs adversely affects performance.
Monday, February 4, 2008
Subscribe to:
Post Comments (Atom)
2 comments:
Hi,
your article was very helpful. However, I am still stuck thinking about the documentation of LoadRunner Scripting language. Is there any place where I can find the complete set of documented LoadRunner Scripting Syntax?
Thanks in advance,
Debjit
Hi,
I'm glad that you found it useful. You can have the complete set of loadrunner functions from vugen function reference. Chaek your installation dir for the chm file.
Post a Comment