Friday, 31 October 2014

Dynamic Item data Load Runner

I want to construct following Itemdata (Name-Value Pair)

"txtEditBookmarkDescription_Row26=LoadTest_7925&txtEditBookmarkDescription_Row26=LoadTest_7925&txtEditBookmarkDescription_Row26=LoadTest_7925&txtEditBookmarkDescription_Row26=LoadTest_7925"

cAllBKNamesis a variable consists of all Names extracted from the response using web_reg_save_param_ex and ordinal is All
cAllBKIDs: is a variable consists of all Values extracted from the response using  web_reg_save_param_ex and ordinal is All

Code:

        char *ItemData;                 //Final String consists of concatenated Name-Value Pairs 
        int count, i, size=0;           //Count : number of Name-Value Pairs to be concatenated
        char *str1, *str2;              //Temporary strings

count = atoi(lr_eval_string("{cAllBKNames_count}"));
        lr_output_message("%d",count);

        for(i = 1; i <= count; i++)
          {
       
                str1=lr_eval_string(lr_paramarr_idx("cAllBKNames",i));
                str2=lr_eval_string(lr_paramarr_idx("cAllBKIDs",i));
                size = size + sizeof("&") + strlen(str1) + strlen("=") + strlen(str2);  // Calculating final size   
          }


  ItemData = (char*)calloc(size, sizeof(char));  // Allocating dynamic memory based on size of  final string                                                                                    
        //Building actual string to ItemData variable

        for(i=0; i< count; i++)
{
str1=lr_eval_string(lr_paramarr_idx("cAllBKNames",i));
                 str2=lr_eval_string(lr_paramarr_idx("cAllBKIDs",i));                
                 strcat(ItemData,str1);
strcat(ItemData,"=");
strcat(ItemData,str2);
strcat(ItemData,"&");
}

lr_output_message("%s", ItemData);

free(ItemData);

No comments:

Post a Comment