Saturday, October 1, 2011

Using Regular expression and SaveLen attribute in LoadRunner

Problem:
How do you capture a variable in LR that has a dynamic right boundary?

Example:
Depending on the data I used in a project (Siebel Project), the right boundary of a row ID that I wanted to capture from a response would change. For example,
1: Data set 1 would return following response - ...*Y1*Y10*1-1YK-49251*11*11*N1*...
2: Data set 2 would return following response - ...*Y1*Y10*1-2XY-45233*11*11*N1*...
3: Data set 3 would return following response - ...*Y1*Y10*1-1KM-72142*11*11*N1*...

In the above response, I needed to capture the row ID "1-1YK-4925","1-2XY-4523" & "1-1KM-7214" respectively. As you can see, the right boundary is different for different data set and therefore just passing left and right boundary values in web_reg_save_param, would fail or/and capture wrong row ID value.

web_reg_save_param("rowID","LB=*Y1*Y10*","RB=1*11*11*N1*",LAST); --Will fail for data set 2 & 3. Same thing will happen if you are using RB from data set 2 and 3.
web_reg_save_param("rowID","LB=*Y1*Y10*","RB=*11*11*N1*",LAST); --will fail for all data sets because an extra character is saved in Temp parameter.

Possible solution:
As you might have noticed, the row ID that we want to capture consists of 10 characters and therefore we could use one of the following approaches to solve this problem:

1: SaveLen attribute- since we know that the number of characters for row ID, we can use SaveLen Attribute in web_reg_save_param function to capture the correct value.

2: Regular expression- Second approach is to use regular expression to capture the row ID. Their is a really good blog written by Dmitry Motevich on how to use regular expression in LoadRunner.

To demonstate the above two approaches in Siebel, I have used three parameters to save the row ID value from the server response (see the image below):

1: SubActivityIDWithoutRegAndNoSaveLen - this parameter is captured using web_reg_save_param without SaveLen attribute. In this case a wrong value is captured.

2: SubActivityIDWithoutRegAndSaveLen - this parameter is captured by passing SaveLen value in web_reg_save_param function. In this case a right value is captured.

3: SubActivityIDWithReg - this parameter is captured using web_reg_save_param and then passed into the regular expression function to get correct rowID. In this case the pattern that matches the above value is "\\d-[0-9A-Z]{3}-[0-9A-Z]{4}" and right value is returned.

From the RunTime Data window you can see that the final value of the parameter captured using the regular expression and SaveLen attribute are the same.


Therefore, depending on your situation, you might be able to use any one of these approaches to capture a value that has dynamic boundaries.

No comments: