Tuesday, April 07, 2009

How to generate random number in a dynamic world

Besides the random number by Loadrunner parameter itself, usually you need to create a Random number of which range is based on the correlated result, for example, you want to check a check-box which number is dynamically changed:



int checkbox_num1=0;
char Randomitem[10];
char RandomStatus[10];
char SRanStatus[10];
...

web_reg_save_param("Checkbox_name1",
"LB=TableSelectCheckbox-_dash_",
"RB=)\" >",
"ORD=ALL",
LAST);

web_submit_data(...
.... );

checkbox_num1 = atoi(lr_eval_string("{Checkbox_name1_count}"));

srand(time(NULL));

if (checkbox_num1>0) {

itoa(rand() % checkbox_num1 +1,Randomitem,10);

sprintf(RandomStatus,"{Checkbox_name1_%s}",Randomitem);

sprintf(SRanStatus, "%s", lr_eval_string(RandomStatus));

lr_save_string(SRanStatus, "CheckboxORD");

}

else if (checkbox_num1==0) {//there is no any suitable value found

lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_AUTO);

}

No comments:

Post a Comment