LoadRunner performance testing system learning tutorial: introduction to the associated function of scripting (7)

In the last issue, we talked about the correlation technology of LoadRunner performance test script writing. In this issue, we will learn about the introduction of the correlation function of script writing.

PART1

Introduction to correlation functions

In the latest version of LoadRunner

The correlation function used is

web_reg_save_param_ex

The correlation function used in the previous version is

web_reg_save_param

But the two functions are not much different in essence. This article mainly introduces the associated function web_reg_save_param_ex

Of course, the associated function web_reg_save_param is still available in the new version.

In the test process, you can insert the associated function by inserting a step. In the tree mode, select the position where the step needs to be inserted, right-click and select the Insert Before menu in the pop-up menu, and the Add Step dialog box will pop up, as shown in the figure.
LoadRunner performance testing system learning tutorial: introduction to the associated function of scripting (7)

在Find Function

Enter the associated function in the drop-down list box

web_reg_save_param_ex

Click the OK button to pop up

web_reg_save_param_ex

The dialog box is shown in the figure.

LoadRunner performance testing system learning tutorial: introduction to the associated function of scripting (7)
The format of the associated function web_reg_save_param_ex is as follows:

intweb_reg_save_param_ex(constcharParamName,[constcharLB, ][constchar*RB,] ,<SEARCH FILTERS>,LAST );

Parameter Description:

ParamName: Indicates the name of the created variable.

LB: The left boundary value of the association rule.

RB: The right boundary value of the association rule.

List of Attributes: Attribute list, the specific content will be introduced in detail later.

SEARCH FILTERS: Specify the string to be searched in the buffer.

LAST: End parameter flag.

1.Parameter Name

Variable name, which means to save the content found in the buffer to this variable.

2.Left Boundary

Set the left boundary value of the search buffer content. When the left boundary value is not set or set to a null value, then the left boundary starts from the beginning of the data.

Example: For the sentence "Where and when do you want to travel?" to be searched, the associated function is as follows:

web_reg_save_param_ex("When_Txt","LB=Where and ","RB= do", LAST); The left boundary value is "Whereand" and the right boundary value is "do", and the search result is "when".

3.Right Boundary

Set the right boundary value of the search buffer content. When the right boundary value is not set or set to a null value, then the right boundary is to the end of the data.

Example: For the sentence "Where and when do you want to travel?" to be searched, the associated function is as follows:

web_reg_save_param_ex("When_Txt","LB=Where and ","RB=", LAST ); The left boundary value is "Whereand" and the right boundary value is a null value, and the search result is "when doyou want to travel?".

As you can see in the figure, whether it is the left boundary value or the right boundary value, there are three settings: whether to distinguish between upper and lower case, whether to search for binary data, and whether to use regular expressions. Regardless of whether the left boundary or the right boundary, the settings of these three options are consistent, so a unified introduction is made.

A.Match case (whether to match case)

Selecting this option means that the case of the left and right boundary values ​​is ignored during the search process, that is, it is not case sensitive.

Example: If you need to find content in the following request.

The associated function code is as follows:

web_reg_save_param_ex( "ParamName=test","LB/IC=USERSession value=","RB=>",SEARCH_FILTERS, LAST);

The result of the association is:

108974.217253949fzAfDzVpDDDzDcpVzHi

Among them, "LB/IC" means that the left boundary value is not case sensitive, that is, the left boundary

“USERSession value=”与“userSession value=”

Is consistent, if case-sensitive, you can not find a matching value.

B.Binary data (binary data search)

If the content to be searched is in non-ASCII format, binary or hexadecimal format, so if you still search by the usual left and right border methods, you cannot find the content you need, and you need to select Binary data. Option to match the content to be searched in binary mode. Generally use "\x" to identify, such as \x37.

Example: For example, the binary content to be checked \xAC\xED\x00\x05\x00.

The correlation function is as follows:

web_reg_save_param_ex( "ParamName=test4","LB/BIN=\xAC\xED\x00","RB/BIN=", SEARCH_FILTERS, LAST);

C.Regular expression (regular expression matching)

Regular expression refers to a single string used to describe or match a series of strings that conform to a certain syntax rule. In the process of performance testing, if the value to be matched is not exact, but a fuzzy query, then regular expressions need to be used for matching at this time.

The metacharacters matched by regular expressions commonly used in LoadRunner are shown in the table.

Meaning of metacharacter 僦

Metacharacter meaning

[Identification of the beginning of the regular expression

] The end of the regular expression flag

() The content included is regarded as a set of content

^The match starts with a certain character, such as ^abc means to find a string starting with abc

$ Match ends with a certain character, such as abc$ means to find a string ending with abc

. Match a character, the character can be any character

? Match the previous character or a group of characters, the number of matches is zero or one. For example, "ab?c" can match "abc" and "ac", and "A(123)?B" can match "AB" and "A123B"

+Matches the previous character or a group of characters, and the matching times are one or more times. For example, "ab?c" can match "abbbc" and "ac", and "A(123)?B" can match "AB" and "A123123B"

*Match the previous character or a group of characters, the number of matches is zero or more times

\ Escape character

| Matches the characters before or after "|", for example, "(ABC)|(123)" can match "ABC" or "123"

4.DFEs

DFEs (Data Format Extensions) file extension format. Many different types of data records are supported in the VuGen generator. With the continuous increase of file formats, the VuGen generator must support these formats. Some formats are proprietary and use custom serialization, but binary codes and some unformatted data are difficult to understand, so VuGen occurs The data format extension function (DFEs) is added to the device, and the data in these formats can be converted, so that the data can be better understood, and the data can also be associated as parameters.

The data extension formats supported by LoadRunner include:

Four formats: Base64 Extension, URL Encodin Extension, JSON Extension and XML Validator Extension

See the table for details.

Table data extension format

Data extension description

Base64 Extension decodes Base64 encoding (Base64 encoding is one of the most commonly used 8Bit byte code encoding methods in network transmission)

URL Encodin Extension interprets URL encoding (URL encoding is a format used by browsers to package form input)

JSON Extension converts JSON data (JSON (JavaScript Object Notation)) is a lightweight data exchange format. It is based on a subset of JavaScript (Standard ECMA-262 3rd Edition -December 1999). JSON uses text that is completely language independent Format, but also uses the habit similar to the C language family (including C, C++, C#, Java, JavaScript, Perl, Python, etc.) to convert to XML format

XML Validator Extension accepts data and checks whether the data conforms to XML syntax, allowing VuGen generator to correlate xpath queries and display its snapshot in the xml view

Such as the following example:

iRetVal= web_reg_save_param_ex("ParamName=newParam", "LB/IC=ll", "RB/BIN/RE=RR", "Ordinal=all", "SaveLen=-1", "DFEs=UrlEncoding", SEARCH_FILTERS, "Scope=body",LAST);lr_output_message("Return value = %d (%s).", iRetVal, iRetVal == LR_PASS ? "LR_PASS" : "LR_FAIL" );

Note: If you need to use the DFEs extended data function, you need to set the [Enable Data Format Extension] checkbox to be available in the Run-time Settings dialog box.

5.Ordinal

Ordinal indicates the position where the matched content appears, the default value is 1 (referring to find the content to be matched, the first occurrence), if the value of this item is set to All, it means that the search in the cache can meet the left and right boundaries And save the found result in a data. If it is set to 1, then the found result will be saved in a variable.

For example, the content of the page to be found is as follows:

Blue Sky Air 0008am$ 0Blue Sky Air 0011pm$ 0Blue Sky Air 0025pm$ 0Blue Sky Air 00311pm$ 0

The correlation function is as follows:

web_reg_save_param_ex("ParamName=WCSParam_Text1", "LB=outboundFlight value="","RB=;", "Ordinal=All", SEARCH_FILTERS, LAST);

The result of the playback is shown in the figure.

LoadRunner performance testing system learning tutorial: introduction to the associated function of scripting (7)
6.Save Offset

Save Offset refers to the offset. When the left and right boundary values ​​are used to match the appropriate string content, you can set the number of characters to be intercepted. The default value is 0, that is, starting from the first position. For example, if the matched string is "soft testing", when Save Offset is set to 0, it will be intercepted from the first digit. If it is set to 2, then it will be intercepted from the third digit, that is, the matched result will be returned as "ft testing".

For example: There is a string "Astra on the TESTSERVER" in HTML, and the associated function is as follows:

web_reg_save_param_ex( "ParamName=WCSParam_Text1","LB=outboundFlight value="", "RB=;", "Ordinal=1", "SaveOffset=2" SEARCH_FILTERS, LAST); 匹配的结果为“ the”。

7.Save Length

Save Length means to set the length of the intercepted string. If set to 10, it means to intercept 10 characters from the matched characters. The default value is -1, which matches to the end of the string. Under normal circumstances, the Save Length property is used in conjunction with the Save Offset property.

For example: There is a string "Astra on the TESTSERVER" in HTML, and the associated function is as follows:

web_reg_save_param_ex( "ParamName=WCSParam_Text1","LB=outboundFlight value="", "RB=;", "Ordinal=1", "SaveOffset=0" "SaveLen=2", SEARCH_FILTERS, LAST);匹配的结果为“on”。

8.Frame ID

When there are multiple frames in the page, if you need to match the data in the frame, you need to specify a specific frame, otherwise the value that needs to be queried cannot be matched correctly. Through the frame ID number, you can specify to access different frames, and the frame ID is the most It can only consist of 7 digits, as shown in the following example.

Table frame ID

Parameter Description

10.0.0.0.0.0.1

1.10.0.0.0.0.1.1

1.20.0.0.0.0.1.2

1.1.10.0.0.0.1.1.1

PART2

Classic use of related technology

The parameters of the correlation function are explained in detail above. In essence, the correlation function is a search function. To put it bluntly, it is to find the required value from the content of the HTML file and save it in a variable or array. From another perspective, in fact, the correlation function can not only match some changing values, but also match some fixed content and save it in a data group for subsequent business use. That is to extend the use of the correlation function, which is often used in business processing.

Example: Take the airplane booking system as an example. Suppose that to realize such a business, after choosing the departure city and arrival city, when choosing a flight, you need to choose the cheapest flight, as shown in the figure.
LoadRunner performance testing system learning tutorial: introduction to the associated function of scripting (7)

Implementation idea: First use the associated function to read the ticket price and flight number in the HTML code, and save the two parts of the data in different arrays; then compare the ticket prices and choose to find the lowest fare element in the array , That is, under the data where the cheapest ticket is located; finally, read the flight number corresponding to the value of the subscript, which is the cheapest flight.

Before using the correlation function to associate the fare and flight number, you must first analyze the left and right boundary values ​​of the fare and flight number. The HTML source code for the flight information is as follows:

Blue Sky Air 1008am$ 386Blue Sky Air 1011pm$ 343Blue Sky Air 1025pm$ 365Blue Sky Air 10311pm$ 315

Analyzing the above source code can find the left and right boundary values ​​of the fare and flight number. The left and right boundary values ​​of the fare are: "center>$" and "", and the left and right boundary values ​​of the flight are "outboundFlight value" =" and ";".

The code of the associated function is as follows

(You can use web_reg_save_param or web_reg_save_param_ex function for association):

Use web_reg_save_param function to associate, the source code of the associated function of fare is as follows:

web_reg_save_param("WCSParam_Text1","LB=center>$ ","RB=</TD>","Ord=All","RelFrameId=1","Search=Body","IgnoreRedirections=Yes",LAST);

The source code of the flight-related function is as follows:

web_reg_save_param("WCSParam_Text2","LB=outboundFlight value=","RB=;","Ord=All","RelFrameId=1","Search=Body","IgnoreRedirections=Yes",LAST);

Use web_reg_save_param_ex function to associate, the source code of the associated function of fare is as follows:

web_reg_save_param_ex( "ParamName=fligthcost","LB=center>$ ","RB=</TD>","Ordinal=All", SEARCH_FILTERS, LAST);

The source code of the flight-related function is as follows:

web_reg_save_param_ex( "ParamName=fligthno","LB= outboundFlight value=","RB=;","Ordinal=All",SEARCH_FILTERS, LAST);

Note: The property of Ordinal must be set to "All" when associating, so that all the values ​​can be matched and stored in an array.

After determining the left and right boundary values, it is necessary to find the flight with the lowest fare among all flights. Because there are 4 flights in total, it is necessary to select the cheapest flight among these 4 flights. The realization idea is to set a flag, assuming the fare The value of the last element of the saved data group is the largest (set the flag as flag), then the other elements in the array are compared with the flag flag in turn. If other elements are smaller than the value of flag, the value in the flag is set to the current value The value corresponding to the array index. The implemented code is as follows:

//Initialize the most expensive ticket, and set the first flight ticket to the most expensive initialized ticket max = atoi( lr_eval_string("{WCSParam_Text1_1}") );//Initialize the flag, the default setting is 1flagno =1;/ /for loop all tickets for(i = 2;i <= atoi(lr_eval_string("{WCSParam_Text1_count}"));i++){sprintf( cost,"{WCSParam Text1 %d}",i );//Compare the first flight Whether the ticket is greater than the value of max, if the value of max is larger, re-assign max if(atoi(lr_eval_string(cost))> max){max = atoi( lr_eval_string(cost) ); flagno = i;}}

After finding the easiest ticket, you can get the subscript of the array. The flight corresponding to the subscript of this array is the cheapest flight. The code for obtaining the flight number is as follows:

//Determine the flight sprintf( flightelem,"{WCSParam Text2 %d}",flagno) through the flag ; lr_save_string( lr_eval_string(flightelem), "flightno");

After obtaining the cheapest fare and flight, put the two parts of information into the submitted information and submit it as a client request. The specific code is as follows:

web_submit_data("reservations.pl_3","Action=http://127.0.0.1:1080/WebTours/reservations.pl","Method=POST","RecContentType=text/html","Referer=http://127.0.0.1:1080/WebTours/reservations.pl","Snapshot=t24.inf","Mode=HTTP", ITEMDATA,"Name=outboundFlight","Value={flightno};{flightnocost};10/26/2011", ENDITEM,"Name=numPassengers","Value=1", ENDITEM,"Name=advanceDiscount","Value=0", ENDITEM,"Name=seatType","Value=Coach", ENDITEM,"Name=seatPref","Value=None", ENDITEM,"Name=reserveFlights.x","Value=57", ENDITEM,"Name=reserveFlights.y","Value=13", ENDITEM, LAST);web_submit_data("reservations.pl_4","Action=http://127.0.0.1:1080/WebTours/reservations.pl","Method=POST","RecContentType=text/html","Referer=http://127.0.0.1:1080/WebTours/reservations.pl","Snapshot=t25.inf","Mode=HTTP", ITEMDATA, "Name=firstName","Value=test", ENDITEM,"Name=lastName","Value=test", ENDITEM,"Name=address1","Value=", ENDITEM,"Name=address2","Value=", ENDITEM,"Name=pass1","Value=test test", ENDITEM,"Name=creditCard","Value=", ENDITEM,"Name=expDate","Value=", ENDITEM,"Name=oldCCOption","Value=", ENDITEM,"Name=numPassengers","Value=1", ENDITEM,"Name=seatType","Value=Coach", ENDITEM,"Name=seatPref","Value=None", ENDITEM,"Name=outboundFlight","Value={flightno};{flightnocost};10/26/2011", ENDITEM,"Name=advanceDiscount","Value=0", ENDITEM,"Name=returnFlight","Value=", ENDITEM,"Name=JSFormSubmit","Value=off", ENDITEM,"Name=.cgifields","Value=saveCC", ENDITEM,"Name=buyFlights.x","Value=41", ENDITEM,"Name=buyFlights.y","Value=17", ENDITEM, LAST);

This example is a situation that may be commonly used in work, and the correlation function is usually used to improve the business process.

PART3

The difference between association and parameterization

Parameterization and correlation methods are introduced in detail, but many friends are easy to confuse the content of the two. In this article, the differences between the two are introduced in detail. The main differences include the following:

1. Different ways of data processing

The parameterized data is submitted by the client to the server, and the association needs to obtain the data that the server returns to the client. During parameterization, the parameterized data will be submitted to the server through web_submit_data. The parameterized strategy comes from the relevant setting options. The associated data is returned from the server to the client. It is a set of verification information for submitting the request, so processing The associated data must be obtained from the information returned by the server.

  1. Is the processed data certain

The parameterized data is known by the test engineer, that is, the test engineer knows what data needs to be parameterized to meet the needs of the business. The specific data to be used for parameterization depends on the needs of the business; and the content of the associated data It is unclear, so it can only be determined by the left and right boundary values. The parameterized data is static, that is, the submitted data can be represented statically, but the associated data is dynamic, that is, the principles between them are completely different.

Guess you like

Origin blog.51cto.com/14645850/2540939