What are the step to modify the script in VuGen after recording?
Ans: In order to modify a script in VuGen, the following options are available:
- Add Transaction
- Parameterization
- Correlation
- Variable declarations
- Rendezvous Point
- Validations/Checkpoint
Correlation is the concept to handle the dynamic values which are generating by the server. You can conduct the correlation in 2 ways:
1. Auto Correlation.
2. Manual Correlation.
what are the areas you can do correlation :-
- List box
- Radio Buttons
- Check Boxes
- Links
- Item Data
- Time Stamp
- Cookies
- Checksums
- Session ID's
We can find the Correlation values in multiple places :-
- Code generation Logs
- Snapshot view (or) Tree View
- Data Return by server -Runtime settings and Replay the script
- Page View sources.
- Capture entire response using Empty LB, Empty RB and identify the RB & LB.
1. Auto Correlation:
A. Automatically handle the dynamic values.
Process:
1) Record the script.
2) Replay the script.
3) Click the design studio.
4) Choose the dynamic value.
5) Click on “Correlate button”.
B. By using Correlation Rules.
Note: A design studio or correlation log compares record time response with replay time response dump the differences into the correlation log or design studio.
2. Manual Correlation
Manually we have to handle the dynamic values. Whatever the steps performed by autocorrelations steps will be performed manually.
Process:
Step1: How to identify the dynamic values in a script?
Sol: 1. Record the same business scenario twice with 2 sets of data & compare both of them using “beyond-compare” or “www.text-compare.com” or Tools “Windiff” (default).
Which values reported differently those values will be considered as dynamic values.
2. Code generation Logs
3. By Using Snap shots
4. By using Runtime settings -> logs -> Extended logs -> Data returned by server logs
5. By using Reply Logs
6. By using Developer tool from Brom Browser.
Note: Which values are generated by the server those values will be considered as dynamic values.
Step2: How to identify the left text & right text for a dynamic value?
Sol: web_reg_save_param(“parameter_name”,”lb=”,”rb=”,LAST);
Copy the dynamic value.
Go to generation log identify first occurrence of the dynamic value.
Copy the left text & right text of the dynamic value.
Step3: Where to write the function?
web_reg_save_param(“parameter_name”,”lb=userSession” value=” ”,”rb=”/>”,LAST);
Sol1: Execute the script in full mode (F4 : LOG ->Extended Log->Enable All Options). Identify the dynamic value based on the left boundary or right boundary in Replay log. Double click on the same line which will assist you to where to write the function or for which request the dynamic value was generated.
Sol2: once you identified the dynamic value in generation log place the cursor on the same line and search for “web_” or “ENDED” then copy the request and search for the same in script. On top of the same request u can place the function.
NOTE: Generation log contains response and request which never change.
Step4: Substitution
Sol: You can substitute the parameter name where ever the dynamic value is present in script using control+H.
Correlation Function with all Arguments
1. ORD:(Ordinal)
ORD : Match Cases(“Number of Occurrence”).
By default ORD=1.
Ex:
Ord=10 stands for 10th occurrence.
Ord=ALL stands for captures all values based on LB & RB.
Whenever you written ORD=ALL your parameter become an Array. It holds all
the values with the name of parameter-1, parameter-2 & parameter-N.
Note: Variable_count let we know the length of an Array.
2. Save Length:
It Capture the length of Correlation value
Allow you to capture specific no. of characters from dynamic value based on LB and RB.
Ex: savelen=3
By default savelen=”-1”.
3. Save offset:
It ignore the number of characters from immediate constant LB
It will specify the no. of characters it supposed to skip from the dynamic value.
By default saveoffset=”0”.
EX: saveoffset=3 (It skips 3 char)
Eg : input Type= "hidden" Name="SKU20" Value="16544094" ......
web_reg_save_param("corr_Name",
"LB= input Type= "hidden" Name="SKU",
"RB=\"",
"Savelen=8",
"Saveoffset=11",
LAST);
here savelen =8 means the correlated value 16544094
here saveoffset =11 means the Dynamic Boundary length value (including Space) 20" Value="
Note : if the length of the captured string in correlation parameter is greater than 256 bytes then we need to specify web_set_max_html_param_len("9999"); at the beginning of the action.
4. Not found:
Whenever boundaries is not matched it will show error
Notfound : Error -> script stopped if it is error
Notfound : Warning -> Script will continue even it is error also.
By default Notfound=”error”.
If the either LB or RB is not present in the response script will through the error like “No match found for the requested parameter”.
Notfound=”warning”.
If you would like to continue the script execution, even LB or RB is not available in the response you have to use warning.
5. Search:
It is an optimization technique. This will instruct the user to search for LB & RB in a
specific location.
By default search=ALL(Body + Header).
Ex: Search= headers: - it will search for LB n RB in only on header
Ex: Search= Body: - it will search for LB n RB in only on body
6. RelframeID:
This is also optimization technique. Specifying to capture the dynamic value from a specific frame.
Ex: RelframeID=1.2.1
HTTP Status Codes:
100 - Request successfully delivered.
200 - Response received successfully.
300 - Received response but it was redirected response.
400 - Invalid request.
500 - Application itself not available.
7. Ignore Redirection:
By default ignore redirection= YES
Instructing correlation function to capture dynamic value from a redirected response or not.
8. Convert: When ever the dynamic value is recorded in the format of URL and the captured value in the format of HTML. Use convert argument to convert HTML to URL but did not “Vice-Versa”.
Ex:
123aswbc%20jsae3%
Convert= HTML_TO_URL
HTML - Hyper Text Markup Language
XML - Extensible Markup Language
Regular Expressions:
Whenever you have dynamic LB & RB, we can use regular expressions. This function works on
expression but not on boundaries.
Steps to construct regular expressions:
Step 1: Copy the LB & RB from generation log.
Step 2: Construct the expression.
Step 3: Validate inwww.rubular.com
Step 4: Write web_reg_save_param_regex() function.
Example:
web_reg_save_param_regex(“parameter name = reg_exp”,
“regex=name =\” u[a-z]er[A-Z]ession\” \\value=\”(.*?)\” , LAST);
u[a-z]er[A-Z]ession Function searches for userSession based on this regular expression.
[a-z] Skips any single character in the range a-z
[A-Z] Skips any single character in the range A-Z
Problem:
How to correlate values from response coming from as outside server ?
Correlation rules will not work when attempting to correlate a value from a response that is coming from an outside server(for instance, if a call is being made by the application to bring or some other third party), Manual correlation will nee to be done in this case.
when adding the correlation, make sure that the RelFrameId is set to 'ALL' or that the RelFrameId is left out of the correlation (if not specified the default is set to ALL).
How to select a random value from the correlation parameter in LoadRunner?
Explanation:
Sometimes there is a requirement to pass a random value from a list of dynamic values captured by a correlation function i.e. web_reg_save_param(). Let’s consider a web page has 10 items which could be different for all users. Now, you want to randomly choose 1 item appeared on the web page and place an order. What will be your approach?
Definitely:
You will add a correlation function before the request whose response contains the name of items
You will give “Ord=All” to capture all the name of all the items
web_reg_save_param("c_itemName",
"LB=itemname=\"",
"RB=\"",
"Ord=All",
LAST);
Additional Information: When you give “Ord=All” then the correction parameter (c_itemName) acts as an array and captures all the values which satisfy the left and right boundaries. If you want to choose any specific value then you can append “_<number>” in the correlation parameter and pass into the subsequent request. <number> denotes the place of the item appeared on the webpage.
For example, if you need to pick 2nd value then the correlation parameter will be “c_itemName_2”.
Solution:
To pick the random value from the correlation parameter, you have to use the following statement:
lr_save_string(lr_paramarr_random(“c_itemName”),”randParam”);
where:
lr_paramarr_random: This function returns a random value from the parameter array. The return value will be a ‘String’. In the above example, a random value (string) will be picked from “c_itemName” array.
lr_save_string: This function is used to save a string into a parameter. In the above example, the random value (string) extracted by lr_paramarr_random will be saved in “randParam”.
Now, you can use “randParam” as a parameter in the script which will pass a random value extracted from the list of captured dynamic values.
Problem:
How to select last value from correction parameter list in LoadRunner?
Explanation:
There are some practical scenarios in which the last dynamic value needs to be selected and passed in the next request. Here are some examples:
A random number of values populate in a drop-down and the last value needs to be selected.
A random number of records appear on a page and the last record needs to be picked.
Solution:
To simulate these scenarios, firstly, you need to capture all the dynamic values using “Ord=All” in the correlation function.
web_reg_save_param("c_correlateParam",
"LB=value=\"",
"RB=\"",
"Ord=All",
LAST);
For your knowledge when you choose “Ord=All” then the correction parameter acts like an array. If you want to choose any specific value then you can append “_<number>” in the correlation parameter name. For example, if you need to pick 2nd value then the correlation parameter will be “c_correlateParam_2”.
Now, there are 2 approaches to select the last value from the correction parameter list:
Approach 1:
In the first approach, you need to define two variables at the start and then use lr_paramarr_len and lr_paramarr_idx functions to save it in a C variable. The code is:
int arrLen;
char * lastVal;
web_reg_save_param("c_correlateParam",
"LB=value=\"",
"RB=\"",
"Ord=All",
LAST);
web_submit_form("abc",
.
.
.
.
.
.
LAST );
arrLen = lr_paramarr_len("c_correlateParam");
lastVal = lr_paramarr_idx("c_correlateParam", arrLen);
where:
lr_paramarr_len: This function returns the length of an array which is equal to the number of values stored in that array.
lr_paramarr_idx: This function returns the value available at the specified place in the parameter array.
lr_paramarr_random() Randomly pick one value from the total array list.
lr_paramarr_len() Returns the length of the array means the location of last value. This location is passed in lr_paramarr_idx() which fetch and return the last value of the array. Like this, the last value of the correlation parameter is stored in ‘lastVal’ variable and can be used further in the script.
If i want to get last 2 values then
lr_save_string(lr_paramarr_idx("demo", lr_paramarr_len("demo")), "last value); -- getting last value
lr_save_string(lr_paramarr_idx("demo", lr_paramarr_len("demo")-1), "2nd value);--- getting last two values
Rand(); it is a C function that is used to genearate random Number.
Eg : rand()%30 - it will give use Random Number any where between 0 -29
Eg :
randnum = rand()%30 + 1
lr_save_datetime("%d/%m/%y", date_Now+one_day*randnum, "pDate");
Approach 2:
In the second approach, again two variables need to be defined at the start:
int arrLen;
char lastVal[30];
web_reg_save_param("c_correlateParam",
"LB=value=\"",
"RB=\"",
"Ord=All",
LAST);
web_submit_form("abc",
.
.
.
.
.
.
LAST );
sprintf (lastVal, "{c_correlateParam_%s}", lr_eval_string("{c_correlateParam_count}"));
lr_save_string( lr_eval_string(lastVal) ,"lastValue");
where:
lr_eval_string: This function evaluated the value of _count which is a count of dynamic values captured through correlation function. It is as same as the length of the array.
sprintf: This is a C function which evaluates an LR variable and saves the (last) value into C variable (named lastVal).
lr_save_string: The output of lr_eval_string() which is evaluating the value of lastVal, is saved in an LR variable (named lastValue). Since this is an LR variable so can be used in the script using {“”}.
The difference between both the approaches is
The first method returns the value in a C variable whereas the second method returns the value in the LR variable. You can get the value in C variable using the second method as well.
Q. How to identify what to correlate and what to parameterize?
Ans: All the dynamic values coming from the server should be correlated. You can identify the dynamic values in the following ways:
By replaying the script:
- Replay the script with the same user: You will get dynamic values like the session ID, authentication token etc.
- Replay the script with the different user: You will get user-specific dynamic values like orderID, customerID etc.
By comparing generation and replay log:
- Replay the script
- If it fails at any particular request then look at the generation and replay log of the same request and identify the dynamic value.
Q. What are the correlation functions available in VuGen?
Ans: There are 5 correlation functions available in VuGen.
- web_reg_save_param()
- web_reg_save_param_ex()
- web_reg_save_param_regexp()
- web_reg_save_param_json()
- web_reg_save_param_xpath()
=============
There
are some special characters and cases when specifying the boundaries. Special characters (e.g., '\',
'"\) in the boundaries must be "escaped" by a backslash.
Example:
Recording Log (for Single Protocol), or Generation Log (for Multiple Protocol) |
Left boundary (LB) |
Right boundary (RB) |
Value="57685" |
"Value=\"" |
"\"" |
Value_"\item\"value’7875’ |
"Value_\"\\item\\\"value’ " |
"’" |
Value=
"7898756" |
"Value=\r\n\"" |
"\"" |
========
Attributes of ‘web_reg_save_param_regexp’:
a. Parameter Name: The name of the correlation parameter which saves the dynamic value. This is a mandatory field.
b. RegExp: This is a mandatory attribute. In this attribute, you have to write a regular expression to capture the dynamic data. Refer to the post to learn how to write regular expression?
c. Group: This is an optional attribute. Group attribute provides the option to capture multiple dynamic values using the same regular expression. If you pass 0 (zero) then it saves the entire expression along with the specified text. The maximum value is 10. Example: If you have specified the regular expression as given below and you need to capture SurName, then Group will be 2
"RegExp=Name=(.*?) and SurName=(.*?)",
d. DFEs: This is an optional attribute. It is a comma-separated list of Data Formats Extensions that are to be used before the required search operation is to be performed.
e. Ordinal (ORD): This is an optional attribute. It is used to capture dynamic value on a specific occurrence. If you specify the value of Ordinal (ORD) =ALL then all the occurrences of the matched boundary are saved in an array. Each element of the array is represented by the ParamName_index. In the following example, the parameter name is c_custID:
web_reg_save_param_regexp(
"ParamName=c_custID",
"RegExp=customerID=(.*?);",
"NotFound=warning",
"Group=2",
"Ordinal=ALL",
LAST);
The first match is saved as c_custID_1, the second match is saved as c_custID_2, and so forth. You can retrieve the total number of matches by using the following parameter ParamName_count. For example, to retrieve the total number of matches saved to the parameter array you can use the below statement:
customerCount=atoi(lr_eval_string("{c_custID_count}"));
h. Warn if text was not found (Default is Error) (NotFound): This is an optional attribute and has ‘Error’ as a default value. This option handles the situation when the defined boundary does not match and generates an empty string. It has the following input options:
ERROR: This is a default value. When a boundary is not found then LoadRunner highlight it as an error in the log.
WARNING: LoadRunner does not issue an error. If the boundary is not found, it sets the parameter count to 0 and continues executing the script. The ‘warning’ option is good when you want to see whether the string was found or not, but do not want the script to fail.
Note: If ‘Continue on Error’ option is enabled for the script then even when NOTFOUND is set to ‘ERROR’; the script continues when the boundary is not found, but an error message is written to the Extended log file.
i. Scope: This attribute comes under ‘Filters (SEARCH_FILTERS)’ option. This is also an optional attribute with default value “All”. It specifies the scope of the search of dynamic value within the response. The input options are:
All: The scope of search is body, headers, and resources
Headers: It indicates to search only in the headers
Body: The scope of the search is only body, not headers
Cookies: The scope of the search only cookies.
j. Header Name (HeaderNames): To enable this attribute you need to select ‘Scope’ type as Headers. Here, you can provide a comma-separated list of HTTP response header names then LoadRunner will search the dynamic values only in the specified headers. This is an optional attribute.
k. RequestURL: The dynamic values will be searched only in the responses of specified requests. The URL can contain the * wildcard. It is specially used to correlate the value coming in the response of flex_amf_call.
l. Content Type (ContentType): LoadRunner searches the dynamic value in the responses with the specified ContentType header. The ContentType can contain the * wildcard. This is an optional attribute.
m. Frame ID (RelFrameID): This is an optional attribute. The hierarchy level of the HTML page relative to the requested URL. The possible values are ‘All’ or a number.
Note: GUI level scripts do not support RelFrameID.
n. Ignore Redirection (IgnoreRedirections): This is an optional attribute with default value “No”. The inputs are:
Check (Yes): By setting the ‘IgnoreRedirections=Yes’, it instructs LoadRunner not to search the dynamic value in the response of the redirected request. You can identify the redirected request by its response code HTTP 3XX.
Uncheck (No): LoadRunner even searches the existence of dynamic value in the response of the redirected request.
Difference between web_reg_save_param(); and web_reg_save_param_regex();
ans :
- Escape Character \
- Convert Attribute
- Parameter Name
Q :. If the LB or RB is keep on changing. What is your approach to capture the dynamic value?
Answer:
Sol-1: If the dynamic LB is static use “Save offset” argument.
Sol-2: Use Flag system.
Flag System: Any dynamic number is a part of LB we can use Flag System.
Eg : H1I tvs Welcome.
H2I suzuki Welcome.
Sol: web_reg_save_param(“parametername”,”LB/DIG=H#I”,”RB=Welcome”,LAST);
Q : What is your approach if LB or RB isn’t present for a dynamic value?
Answer:
If the LB isn’t available take any static text from the above line pass it as a LB & identify exact LB from the capture value & pass it as LB.
If the RB isn’t present in the dynamic value take any static text from the below line & pass it as a RB & identify exact RB from the capture value & pass it as a RB.
Q : . Why correlation function is keep on failing?
Answer:
- Invalid LB or RB.
- Function location might be wrong.
- May be your trying to capture more than 256 characters.
- May be the dynamic value itself not available the response.
Q: How will you handle the situation in scripting where for your mailbox you have to select any one mail randomly to read?
Answer: For this we will record the script for reading the first mail. Try to find what is being posted in the request to read the first mail such as mail ids or row no. From the post where a list of emails is reflecting, we will try to capture all the email ids row no with correlation function and keeping Ordinal as All i.e. ORD=All. Replace the requested email id in the read post with any of the randomly selected email id from the list of captured email ids.
No comments:
Post a Comment