Issue with the logic in LoadRunner script

1.6k views Asked by At

I have scripted a web protcol based application flow where in I have to select 20 reports to download. The ReportIDs are shown in the request. I am customising the request so that the request picks up 20 Reports(ReportID) which are either EXCEL or CSV(ReportOutput) and the status is success(ReportStatus). I have captured the LR params thru traditional "wsrp" successfully with Ord=All and here is my logic

int i;
int count=0;
char ro_buffer[25],rs_buffer[25];
lr_save_string("","R_buffer");

for(i=0;i<=atoi(lr_eval_string("{ReportID_count}");i++)
{
sprintf(RO_buffer,"%s",lr_paramarr_idx(ReportOutput,i))
sprintf(RS_buffer,"%s",lr_paramarr_idx(ReportStatus,i))
if((lr_eval_string(ro_buffer)=="EXCEL" || lr_eval_string(ro_buffer) =="CSV") && lr_eval_string(rs_buffer)=="S")
{
count++;
if(count>20) break;
lr_param_sprintf("R_buffer","%s%s%2c",lr_eval_string("{R_buffer}"),lr_paramarr_idx(ReportID,i));
 }
}

In the above code, vugen is not executing the code inside the if block even when the condition satisfies, that is, when the report output format is either "EXCEL" or "CSV" and report status is "S". Even from the server response I see the values deducing successfully as per the if block. I also used lr_param_sprintf syntax in place of sprintf but the situation is the exact same. But no use Not able to get what the missing point is.... Need help on this..

2

There are 2 answers

2
James Pulley On

Four issues.

  1. As a performance engineer take the hit outside of the for loop to cast the string to integer once. We should be engaging in performance best practices just like any other developer

  2. The string your are building with sprintf() doesn't include the curly braces "{%s}" which are needed with lr_eval_string("{paramname}");

  3. You have ro_buffer in your evalaution expression, but the sprintf() expression uses RO_buffer (notice upper case). Variables are case sensitive in C

  4. Your expression will not work to compare two strings. Take a look at strcmp() - String Compare.....

1
Michael Galos On

You want code that looks something like this:

int i;
int count=0;
char ro_buffer[25],rs_buffer[25];
lr_save_string("","R_buffer");

for(i=0;i<=lr_eval_int("{ReportID_count}");i++)
{
    if (((strcmp(lr_paramarr_idx("ReportOutput",i),"EXCEL")) == 0) & ((strcmp(lr_paramarr_idx("ReportOutput",i),"CSV")) == 0) & ((strcmp(lr_paramarr_idx("ReportStatus",i),"S")) == 0)) {
        count++;
        if(count>20) break;
        lr_param_sprintf("R_buffer","%s%s%2c",lr_eval_string("{R_buffer}"),lr_paramarr_idx(ReportID,i));
    }
}

I haven't tested this at all. You might want to be careful with the index for ReportOutput, ReportStatus and ReportID which may not align depending on your regular expression. You may need a new 'i' index or two.