LoadRunner performance testing system learning tutorial: scripting checkpoint function (2)

Last issue talked about the LoadRunner performance test script writing, this issue we will talk about the checkpoint function. Let's study together!

Checkpoint function

There are two commonly used checkpoint functions: web_find() and web_reg_find().

web_find() function
The function of this function is to find the corresponding content in the page. The meanings of common parameters are as follows:
web_find("Text Check", //Checkpoint step name
"RightOf=Go to", //Define the right boundary of the search string
"LeftOf=page", //Define the left boundary of the search string
"What =Home", //Define check string content
LAST);
When using this function, pay attention to the following issues:
1. This function can only search for scripts recorded in HTML mode.
2. The function must be searched after the content of the page is displayed, so the function must be written behind the page where the content is searched.
3. The content check option must be enabled. In Run-time Settings→Preferences, select the Enable Image and text check check box, otherwise the search function will not be executed, as shown in the figure.
LoadRunner performance testing system learning tutorial: scripting checkpoint function (2)
4. This function is not supported in VB and Java syntax.
This function has the following two shortcomings:
1. The execution efficiency is low.
2. The search result is not returned. For example, to check how many virtual users have successfully logged in, this function cannot be done, and further operations are required to achieve it.

web_reg_find() function

This function is to find the corresponding content in the cache. It is a registration function. Common parameters and meanings are as follows:

web_reg_find("Text=Welcome", //Define the content to be searched
"SaveCount=Welcome_Count", //Define the search count variable name
"Search=Body", //Define the search range
LAST);
This function must be written in the search content Before the request, it is generally written before the following six functions: Web_custom_request(), web_image(), web_link(), web_submit_data(), web_submit_form(), web_url().
The SaveCount parameter is used to record the number of times that the content in the cache is found. Therefore, this parameter is often used in practical applications to count the number of successful searches, and then to determine whether the content you want to find is really found.
Below is an example.
web_reg_find("Text=Welcome",
"SaveCount=Welcome_Count",
LAST);
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=jojo", ENDITEM,
" Name=password", "Value=bean", ENDITEM,
"Name=login.x", "Value=35", ENDITEM,


if (atoi(lr_eval_string("{Welcome_Count}"))> 0){
lr_output_message("Log on successful.");
} //Judging if the value of the count variable Welcome_Count is greater than 0, then output the successful login in the log
else{
lr_error_message( "Log on failed"); //On the contrary, log in failure will be output in the log
return(0);
}
Although web_find() and web_reg_find() are both checkpoint functions, there are differences between the two functions. The main differences are as follows Several points:
1. The two functions are of different types, web_find is just a normal function, and web_reg_find is a registered function.
2. The content check option must be turned on when using the web_find function, while the web_reg_find function does not have this restriction.
3. The web_find function can only be recorded in the script based on HTML mode when recording, while the web_reg_find function does not have this restriction.
4. The web_find function searches the content in the returned page, and the web_reg_find function searches in the cache.
5. The web_reg_find function has higher execution efficiency than the web_find function.

Using checkpoints to determine the end of a transaction
The purpose of checkpoints is to verify whether the business is successful. How to use checkpoints to verify the success of the business? The need to verify whether the business is successful is to determine the end of the transaction status through checkpoints.
The following is the parameter format of the checkpoint function:
web_reg_find("Text=Welcome", //Define the content to be searched
"SaveCount=Welcome_Count", //Define the search count variable name
"Search=Body", //Define the search range
LAST) ;
There is a very important parameter SaveCount in its function. This parameter is used to count the number of times the data to be checked is found. If you need to determine whether the business is successful, then the data to be checked must be found at least once, so that Ensure that the business is handled correctly. For example, the login function of the flight booking system needs to confirm that the login is successful, then at least the login user name must be found on the login success page (at least once), so as to ensure that the login business is successful.
Take the login function of the above airplane booking system as an example, first insert a checkpoint, and the script for inserting the checkpoint is as follows:
web_reg_find("Search=Body",
"SaveCount=no", //The content that will be checked (test1) The number of times is stored in the variable no
"Text=test1", //The content to be checked is test1
LAST);
Next, it is necessary to determine whether the value of the variable no is greater than or equal to 1, if it is greater than or equal to 1, then the end state of the transaction will be logged Set to LR_PASS, otherwise set the end status to LR_FAIL, the modified code is as follows:
//Use the lr_eval_string function to read the value of the variable no. Since the value read by the lr_eval_string function // is a character type, it needs to be converted to an integer type so that it can be compared if (atoi(lr_eval_string("{no}")) )>=1) {lr_end_transaction("Login", LR_PASS);} else{ lr_end_transaction("Login", LR_FAIL); }
The value of the variable no is greater than or equal to 1, because in some cases, the value may be found There is more than one, so it is generally judged whether it is greater than or equal to 1.
The modified complete code is as follows:
web_submit_data("login.pl",
"Action= http://127.0.0.1:1080/WebTours/login.pl ",
"Method=POST",
"RecContentType=text/html",
" Referer= http://127.0.0.1:1080/WebTours/nav.pl?in=home ",
"Snapshot=t9.inf",
"Mode=HTTP",
ITEMDATA,
"Name=userSession", "Value={WCSParam2 }", ENDITEM,
"

"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=46", ENDITEM,
"Name=login.y", "Value=6", ENDITEM,
LAST);
web_concurrent_start(NULL);
web_url("nav.pl_2",
"URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/login.pl",
"Snapshot=t10.inf",
"Mode=HTTP",
LAST);
web_reg_find("Search=Body",
"SaveCount=no",
"Text=test1",
LAST);
web_url("login.pl_2",
"URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/login.pl",
"Snapshot=t11.inf",
"Mode=HTTP",
LAST);
web_concurrent_end(NULL);
web_concurrent_start(NULL);
web_url("flights.gif",
"URL=http://127.0.0.1:1080/WebTours/images/flights.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t12.inf",
LAST);
web_url("itinerary.gif",
"URL=http://127.0.0.1:1080/WebTours/images/itinerary.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t13.inf",
LAST);
web_url("in_home.gif",
"URL=http://127.0.0.1:1080/WebTours/images/in_home.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t14.inf",
LAST);
web_url("signoff.gif",
"URL=http://127.0.0.1:1080/WebTours/images/signoff.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t15.inf",
LAST);
web_concurrent_end(NULL);
if (atoi(lr_eval_string("{no}"))>=1) {
lr_end_transaction("Login", LR_PASS);
}
else{
lr_end_transaction("Login", LR_FAIL);
}
web_url("SignOff Button",
"URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t16.inf",
"Mode=HTTP",
LAST);

Guess you like

Origin blog.51cto.com/14645850/2535096