Custom HTTP request for LoadRunner
The same pattern is used for performance test development scripts. The typical business logic scenario that is specified during a performance test plan is recorded to form a basic script skeleton.
The script needs to be edited to meet the performance test requirements, and the editing scripts need to master the techniques of parameterization, correlating Dynamic Data, and adding logic controls.
If you cannot handle the recording and editing of a script, it is not possible to continue the performance test effectively and successfully. What is parametric data and dynamic Data?
This data will be sent to the Web server as part of the HTTP request data, but there must be a difference between the two.
When you record a business logic script, the generated script contains the values that were actually used during the recording.
Do not parameterize this script can still replay, do not correlate Dynamic data, replay script will be problematic. In the Department
The same script is executed by many virtual users, the application system now uses a variety of
The caching mechanism is designed to not use the same data, which is inconsistent with the actual usage environment of the application system, which leads to performance measurement
Test results are not credible. To solve such problems, we parameterize and replace the recorded values with parameters. Parametric data also has
Different types, such as logged-in users and passwords, must be registered users supported by the system and need to be from a database table
Read. Other forms have text input boxes that may allow arbitrary input of data. The data that needs to be associated is the response from the server
Gets the data that is sent to the server in a later request. This LR API can be used from the Web_reg_save_parm ()
Gets the dynamic data stored in the server response. Dynamic data is typically logged into a later process after some data is deleted or audited
Links and other circumstances.
This document introduces Dynamic Data arrays and custom HTTP requests in conjunction with instances. Performance tests for demo use
The tool is LR8.0, the Web application that is used is the tool comes with the mercurytours Web system, the version inconsistency, may cause this
The script in the document does not run correctly. Mercury The tours system is simple and offers flight bookings (Flight menu)
and cancellation of flight bookings (Itinerary menu) two functions. You need to register yourself to log in to the system to use these features. which
To cancel a scheduled flight: Log in to the system-click the Itinerary menu-Select a booked flight record-click the button
"Cancel checked reservations" to cancel the flight. 1:
Now there are five flight reservation records in the system, follow the procedure above, record the LR script cancel a booking record, 2:
There is a problem when trying to replay the script, 3:
I need to correlate dynamic data. A flight reservation was canceled when the script was recorded, there are now four records,
Continue recording the script once and compare the two script action.c file 4:
, it can be seen that the number of arguments to the LoadRunner function Web_submit_form () is not the same. which
"Name=1" means the flight reservation record, "Value=on" means sending a request to the server to cancel the corresponding flight record.
Try to delete: "Name=4", "value=", Enditem, Replay script this is successful. But we can't do it every time.
Script to make the script playback successful. What to do? We can only parameterize the parameters of the LR API function or correlate dynamic
Data, you can use the HTTP custom request function web_custom_request () in the event that the number of parameters changes
To replace the function web_submit_form (). This demo system was developed using Perl and has not been seen in this case. But also can
Very good demo web_custom_request ().
A brief introduction to the parameters of Web_custom_request () TODO ...
Here's a look at the body part of the request sent to the server, 5:
The corresponding RecordingLog.txt sections are:
[tid=1a8 Action] Sending request to host 192.168.1.101:1080 (6/5/2009 00:45:15)
"1=on&flightid=1494-796-kz&flightid=1494-1565-kz&flightid=1494-2334-kz&flightid=1494-3103-kz &FL "
"ightid=1494-3873-kz&.cgifields=1&.cgifields=2&.cgifields=3&.cgifields=4&.cgifields=5& Removefli "
"Ghts.x=122&removeflights.y=11"
Where 1=on means to send a request to the server to cancel the corresponding flight record, removeflights.x=122&removeflights.y=11
The record is the position of the button cancel, this does not affect. Flightid and. Cgifields come from the server response and we'll keep this information
There is an array inside, how to judge and manipulate Web_reg_save_parm () refer to other information, no longer described. In Web_url ("welcome.pl",
Before adding:
Added by the Tester Manually.start:
int i,ii,k;
Char tmp[32],tmpp[32];
Char str[1024],strr[1024];
Web_reg_save_param ("Flight_name",
"Lb/ic=
"Rb=\" > ",
"Ord=all",
last);
Web_reg_save_param ("Cgi_field",
"Lb/ic=
"Rb=\" > ",
"Ord=all",
last);
Added by the Tester manually.end!
where "ord=all" means that all the data of the compound left and right boundary are stored in the array.
The following resolves the saved Dynamic Data and encapsulates the body part of the HTTP request:
i = atoi (Lr_eval_string ("{flight_name_count}"));
Ii=atoi (Lr_eval_string ("{cgi_field_count}"));
Lr_error_message ("FFF%d", ii);
strcpy (str, "body=1=on&flightid=");
Lr_error_message ("str:%s", str);
for (k=1;k<=i;k++)
{
sprintf (tmp, "{flight_name_%d}", K);
sprintf (Tmpp, "{cgi_field_%d}", K);
Lr_error_message ("str tmp:%s,%s", tmp,lr_eval_string (TMP));
Lr_save_string (lr_eval_string (TMP), TMPP);
Lr_error_message ("str tmpp:%s", TMPP);
strcat (str, lr_eval_string (TMP));
strcat (str, "&flightid=");
strcat (STRR, "&.cgifields=");
strcat (STRR, lr_eval_string (TMPP));
Lr_error_message ("Str 2:%s", str);
Lr_error_message ("str:%s", STRR);
}
strcat (STR,STRR);
strcat (str, "&removeflights.x=122&removeflights.y=11");
Lr_error_message ("Str 2:%s", str);
Lr_output_message (str);
return 0;
We need to customize the HTTP request function to:
Web_custom_request ("itinerary.pl",
"Method=post",
"Url=http://192.168.1.101:1080/mercurywebtours/itinerary.pl",
"Reccontenttype=text/xml",
"Snapshot=t4.inf",
Str
last);
Now we can replay the script without any problems. Script playback is successful, our text is also
By this end, we are no longer scheduling the script, and we have analyzed the results of the performance test run. of our
The purpose is simply to demonstrate the saving, use, and HTTP custom request function web_custom_request () of the Dynamic Data array.
Custom HTTP request for LoadRunner