Tuesday 4 June 2013

Dynamic boundaries correlation in LoadRunner | How to do correlation when boundaries are changing?

Correlation is nothing but capturing dynamic data from the server response to be used as input in further requests. Although LoadRunner has excellent auto-correlation capabilities, there are occasions when only your scripting skills and the proper application of some sophisticated features can be helpful.

We often deal with dynamic data, but what if the boundaries of the strings are dynamic? What happens if the string's left and right boundaries are dynamic? For complex updates, we first capture a portion of the server response based on some distinctive boundaries determined, and then we extract the required substring from the captured text using functions for handling strings that we've specifically designed.

Suppose you have the response data as follows, where ResponseData is the string you want to capture, but issue is that the left boundary is changing every time. You get the left boundary as axb, where x ranges between 0 and 9, as shown in below example

a0b=ResponseDatarb 
a1b=ResponseDatarb 
a2b=ResponseDatarb
-
--
-
a9b=ResponseDatarb

You can capture the desired string by putting the following correlation function in place, using the /DIG text flag in combination with LB:

web_reg_save_param("C_DynamicBoundaries", "LB/DIG=a#b\=", "RB=rb", LAST);

The corresponding place, which you expect to be dynamically filled in with a digit, should be replaced by a pound sign ( # ).
If letters are changing case, you can modify the function as below to include the /IC flag:

web_reg_save_param("C_DynamicBoundaries", "LB/IC/DIG=a#b\=", "RB/IC=rb", LAST);

Extending the argument further, if there are multiple digits, you have to put a pound sign (#) sing for each digit

A0123b="ResponseData"rb

web_reg_save_param("C_DynamicBoundaries", "LB/IC/DIG=a####b\=", "RB/IC=rb", LAST);

If you expect a place to be filled in dynamically by a digit or a letter, then modify the function to use /ALNUM instead of /DIG text flag, and use caret sign(^) instead of # 

web_reg_save_param("C_DynamicBoundaries", "LB/ALNUM=a^b\=", "RB/IC=rb", LAST);

To deal with the case while, matching alphanumeric dynamic boundaries, there are three versions of /ALNUM flag as – 
ALNUMIC to ignore case, 
ALNUMLC to match only lower case, and 
ALNUMUC to match only upper case. 

But while you do that, keep in mind two things: 
1.One sign (# or ^) for each place
2.If you have a literal # or ^ sign, it will not be interpreted as a literal, if you use the corresponding flags. 
Example: LB/DIG=a#b will not match "a#b".

2 comments:

Unknown said...

This is very useful.
I have a question here. Suppose the number of digits / alphabets differ in dynamic boundaries how should we correlate.

Ex : Server response might vary each time be as below:
1st - a1b=Capturedrb
2nd - a11b=Capturedrb
3rd - a111b=Capturedrb

Unknown said...

Use ^ symbol..it will capture whatever value comes