Consider this.
You have been asked to generate unique UserIDs that is derived for a combination of a unique prefix, the Iteration Number and the Vuser ID. You know the best way to concatenate the three parameters is by using the standard C I/O function sprintf() and the code would look something like this.
char *uniqueId = "AJ101";
char memberId[20];
//Generate Unique MemberIds
sprintf(memberId,
"%s%s%s",
uniqueId,
lr_eval_string("{VUserID}"),
lr_eval_string("{IterationNumber}"));
The parameters {VUserID} and {IterationNumber} can be created in LR and it would look like this in the parameter list.
Okay, now that you have figured out how to generate the memberId, you need to convert this to a loadrunner parameter that can be used just like the normal parameters available in the loadrunner parameter list. (This is now just a variable available in the heap and can be referenced by the variable name memberId and as such cannot be used as a loadrunner parameter as yet.)
This is a situation where you can go for the LR API finction lr_save_string(). The signature of the function is
int lr_save_string (const char *param_value, const char *param_name);
Just replace the char array param_value with memberId and the param_name with the name that you would like to assign to the parameter memberId, you can create a run time variable that can be used just like any other LR Parameter. See the code snippet below.
Here is a snapshot from the replay log for 3 iterations.
This is a typical example and my preferred approach to generate unique userIds that makes me feel 100% percent confident it has not been ever used previously.
1 comments:
Thanks for the example. Just FYI you can have multiple parameters in the string you pass into lr_eval_string. You also can have static strings too. For example:
lr_eval_string("AJ101{VUserID}{IterationNumber}")
would return the same as your call to sprinf. Also if you don't need a local variable you can skip declaring the memberid and do everything in one line:
lr_save_string(lr_eval_string("AJ101{VUserID}{IterationNumber}"), "MemberID");
Hope this helps
Post a Comment