Beruflich Dokumente
Kultur Dokumente
I recorded LoadRunner script for a web server, which contained two special fields
- timestamp and checksum:
web_submit_data("rms.jsp",
"Action=http://eprumossd0010:8400/RMS/jsp/rms.jsp",
"Method=POST",
"RecContentType=text/html",
"Referer=http://eprumossd0010:8400/RMS/html/testFramework.html",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=TIMESTAMP", "Value=1192177661211", ENDITEM,
"Name=CHECKSUM",
"Value=715E19300D670ED77773BBF066DAAAE2866484B8",
ENDITEM,
// others parameters ...
LAST);
Every time a client web browser connects to web server, server gets current time
stamp, calculates checksum and sends them to client. These two fields are used to
identify a current session. In other words, the pair of timestamp+checksum is
analog of session ID.
1. Automatically
2. Manually
I will describe auto-correlation in the future posts. For now, I can say that this is
not ideal solution. Sometimes, it does not work, or works incorrectly.
The differences
are highlighted by yellow. This highlighting means that lines (parameters
values) change from run to run. So, most probably, these values should be
correlated.
Tips: Check Replay (Execution) log carefully. Errors can be there. The
widespread reason of script's errors is an absence of correlations.
Tips: Execute your script with enabled run-time viewer (menu "Tools /
General Options.. / Display"). Any shown errors ("Page not found",
"Session timeout", etc) indicate about potential correlations.
Then execute
script.
Open Replay (Execution) log and find server's response, which contains
dynamic values of TIMESTAMP and CHECKSUM:
Great! Now we
know, where server sends both dynamic values.
And we found the step, that returns these values. This is 13th line -
Action.c (13). Double click the line, containing timstamp's and checksum's
values, 13th line of script will be opened:
web_submit_data("generateChecksum.jsp",
"Action=http://eprumossd0010:8400/RMS/jsp/generateChecksum.jsp
",
"Method=POST",
"RecContentType=text/html",
...
This means that server's response for generateChecksum.jsp page contains
dynamic values which should be correlated.
3. Capture the dynamic value
I will show two ways how to capture a dynamic value:
o Automatic capturing from Tree-view
o Manual from Script-view
These ways are similar enough. Also, they use the same function -
web_reg_save_param.
I start from:
Then:
click "View recording snapshot only" btn (2);
select generateChecksum.jsp page from tree view (3);
select "Body" to view body of server's response (4).
After that
you will see the message box:
You can
create parameter for dynamic value.
If you want to replace all occurrences of dynamic value ("715E19...")
in script, press "Yes" btn.
To not replace all occurrences, press "No" btn.
// [WCSPARAM WCSParam_Text1 40
715E19300D670ED77773BBF066DAAAE2866484B8] Parameter
{WCSParam_Text1} created by Correlation Studio
web_reg_save_param("WCSParam_Text1",
"LB=window.parent.setChecksum(\"",
"RB=\"",
"Ord=1",
"RelFrameId=1",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
Why it is important?
Imagine, that you have the following code:
web_submit_data("somepage",
...
"Name=OrderNumber", "Value=125", ENDITEM,
"Name=UserID", "Value=125",
web_submit_data("somepage",
...
"Name=OrderNumber", "Value={WCSParam_Text1}", ENDITEM,
"Name=UserID", "Value={WCSParam_Text1}",
5. Check changes
After above manipulations, our script will look like:
web_submit_data("rms.jsp",
"Action=http://eprumossd0010:8400/RMS/jsp/rms.jsp",
"Method=POST",
"RecContentType=text/html",
"Referer=http://eprumossd0010:8400/RMS/html/testFramework.htm
l",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=TIMESTAMP", "Value={WCSParam_Text2}", ENDITEM,
"Name=CHECKSUM", "Value={WCSParam_Text1}", ENDITEM,
// others parameters ...
LAST);
Let's run our modified script and see results of capturing from server's
response:
You can see that dynamic values are saved to parameters and their values
are substituted instead of parameters in scripts. Great! We have just
correlated our script and it is working now!
Introduction:
The present article is a summarizing of the LoadRunner Regular Expressions
challenge and its results. Also, I added code for RegExp patterns/subpatterns
matching.
All LoadRunner Regular Expressions functions are shown with examples.
Outline:
I thanks Charlie Weiblen and Tim Koopmans for the solution. I modified it
slightly.
So, here it is:
1. Download and unpack Binaries and Developer files for PCRE (Perl
Compatible Regular Expressions).
These and others files are available on Pcre for Windows page.
2. Unzip downloaded archives into c:\pcre
lr_load_dll("c:\\pcre\\bin\\pcre3.dll");
if (regcomp(&re, pattern, 0) != 0)
return 0; // Report error
if (rc != 0)
return 0; // Report error
else
return 1;
}
It can be helpful, when you verify in LoadRunner that the text (RegExp
pattern) matches the text on a downloaded page.
I tested the match() function with different patterns and subject strings:
Result of Is correct
# Subject string Patterns
match() result?
1 abcdef b(c(.*))e 1 Yes
2 abcdef b(z(.*))e 0 Yes
3 2008 \\d{2,5} 1 Yes
4 2008 \\d{5} 0 Yes
5 abc 1st of May 2008xyz \\d.*\\d 1 Yes
7. Note: Since LoadRunner uses ANSI C language, please do not forget to
double backslashes (\\). For example, to match any digit character (0-9),
use pattern "\\d".
o \d.+([A-Z]\w+)\s+\d{4}
//////////////////////////////////////////////////////
////////////////////
/// 'matchex' (EXtended) function matches a 'pattern'
against a given 'subject'
/// It returns number of matches:
/// 0 - for a non-match or error
/// 1 and more - for successful matches
int matchex(const char *subject, const char *pattern,
int nmatch, regmatch_t *pmatch)
{
int rc; // Returned code
regex_t re; // Compiled regexp pattern
lr_load_dll("c:\\pcre\\bin\\pcre3.dll");
if (regcomp(&re, pattern, 0) != 0)
return 0; // Report error
if (rc < 0)
return 0; // Report error
return rc;
}
2. Let's run sample LoadRunner script and check the result:
matchex()
function returns a number of matched patterns/subpatterns and fill an
array in with information about each matched substring.
This info contains the offset (rm_so) to the first character of each
substring and the offset (rm_eo) to the first character after the end
of each substring, respectively.
Note1: The 0th element of the array relates to the entire portion of
string that was matched.
Note2: Subsequent elements of the array relate to the capturing
subpatterns of the regular expression.
Note3: Unused entries in the array have both structure members set to
-1.
The replay
log shows offsets for matched substrings:
o Action.c(7): Matched 3 patterns
o Action.c(10): Start offset: 1, End offset: 6
o Action.c(10): Start offset: 2, End offset: 5
o Action.c(10): Start offset: 3, End offset: 5
Start offset: 1 and End offset: 6 match substring "bcdef".
Note4: End offset is the first character after the end the current
substring. That's why character "g" (with index 6) is not a part of matched
string.
As I've written in Note1, "bcdef" is the entire portion of string that was
matched.
Others items from an array relate to matched subpatterns.
It's easy to get out the order of subpatterns. Just look through your pattern
from left to right. When you find an open parenthes, this is a start of the
current subpattern.
Subpattern can be embedded.
Another example:
• \d.+([A-Z]\w+)\s+\d{4}
Summary:
I've explained, shown and demonstrated how to use Regular Expressions
(RegExp) in LoadRunner.
I hope, this knowledge will help you to create advanced LoadRunner scripts.
Related articles:
3……Memory Leaks
Today, I plan to share my experience on the memory leaks detecting. This article
is a step-by-step instruction on how to use HP/Mercury LoadRunner to perform
load testing for the purpose of memory leaks discovering.
The task:
It needs perform testing of Web server to discover memory leaks.
The solution:
Actually, I will explain different tricks and features of VuGen scripts in the
further posts.
2. Create LoadRunner Controller scenario for your application using the
VuGen scripts.
Here it is:
The following actions are easy. I will add the name of server where the
application (Web server in my case) will be run. This server can be a
remote one. In this case, you have to make sure that LoadRunner will have
an access to get info from the remote computer. Usually, I provide
administrator rights for user which executes LR scripts.
After that I select counters I want to measure during the load testing:
So, "Windows Resources" dialog looks like:
Also you may wish to add "Private Bytes" counter. Description for each
counter is available on "Windows Resources" dialog. Obviously that the set
of counters depends on the requirements and software to be tested.
Pay attention... If you select the "Windows Resources" graph, the list of
counters will be shown in the lower part of the LoadRunner Controller:
5. So, now Dev team has to fix the problem in the "RService" process.. The
last graph shows the results of load testing perfomed on the fixed
application:
Today, I will describe how to use LoadRunner for broken links detection.
'Broken' link is 'not valid' link. This link usually returns 404 Error - "Page not
found".
Another side of broken links is that images other resources are not displayed.
Using LoadRunner for broken links detection can be helpful, when you perform
load testing of a site and you have to be sure, that all pages, images, applets, and
other resources are available during the high server loading.
1. Script recording
2. Script execution
'Recording Options' dialog opens. Here, set 'Add comment to script for
HTTP errors while recording' option:
Now, you are ready to record your script. Click 'OK' button on 'Recording
Options' dialog and start recording.
If LoadRunner find any HTTP errors, it will include comment into VuGen
script.
My application had some problems - there were several broken links for
images there. So, LoadRunner generated the following script (click the
image to view enlarged):
As you see, my
application had several broken links to images and LoadRunner detected it
successfully. Also, you can find the point, where these broken links were
used. This is previous function - web_url.
Tips: For detailed info on HTTP status codes read this article from
wikipedia and this one from w3.org.
Tips: Read about the most 'popular' HTTP status code - 404.
You have to set appropriate option only. LoadRunner will do the rest :)
After Analysis completed working, custom HTML report should be created and
exported automatically and be sent with email. After that, next load test can be
started from bat-file. So, there are no any pauses for tester's intervention should
be.
Actually, any custom report can be created manually... I added manually new
graph ("Windows Resources"), deleted unnecessary pages, generated HTML
report, saved it, attached to email and sent it.
Above process requires tester's time (= mine). I'm lazy man and don't like
wasting my time for such routine actions.
I will show how to edit a default report and save it as a template. After that, we
will learn how to start LR Analisys from command line and how to work with a
saved template.
The new graph ("Windows Resources") adding is also intuitive. Just right-click
on "Graphs" item and select "Add New Item / Add New Graph":
After that you can select new graph to added. In my case, I selected "Windows
Resources" graph:
After that I rearrange the current list of graphs. For that just drag any item
(graph) and drop it to required place. It's easy, really :)
After these manipulations, the list will be the same I wished:
So, custom HTML report is ready without tester's intervention! Next LoadRunner
test can be started from command line.
For example:
• starts
• opens Controller scenario
• executes it
• saves results to folder 'C:\Temp\LR_Res\result_0'
Well, let's see different variants of how to open and run LoadRunner Controller
script:
The problem:
This is a frequently asked question - why file downloading from a browser page
(right mouse click, then "Save Target As...") was not recorded in LoadRunner
VuGen script?
LoadRunner records file transferring from server and does not record file
saving.
1. web_url("logo.gif",
2. "URL=http://www.google.com/intl/en_ALL/images/logo.gif",
3. "Resource=1",
4. "RecContentType=image/gif",
5. "Snapshot=t1.inf",
6. LAST);
To save this image as file to local disk, we have to perform these steps:
Then execute script containing initial web_url function, and open Replay log:
Tips: The simplest way - strlen function - is not correct. Imagine, that that
captured data contains embedded NULL characters ('\0'):
"123\0qwe"
The real size of captured data = 7 bytes ('1', '2', '3', '\0', 'q', 'w', 'e').
But strlen function will return value 3, because it counts bytes before the first
NULL character ('\0').
lr_eval_string_ext function copies captured data into szBuf array and places a
size of captured data into nLength variable. That's easy, I hope :) If not, Help will
help :)
Tips: There is another way to get known the size of file to be downloaded.
Remember, that server returned the length of file (Content-Length: 8558). So,
you can extract this value using Correlation.
And the last action is to save binary data from szBuf array into a local file. I used
standard fwrite function from C programming language:
fwrite(szBuf, len, 1, hFile);
Execute the source code, and you will see, that new file will be created and
saved automatically - "C:\LogoImage.gif". And this is what we needed -
Google's logo image.