51Testing软件测试论坛

标题: 如何随机选取web_reg_save_param保存的函数 [打印本页]

作者: 城邦    时间: 2013-5-7 09:27
标题: 如何随机选取web_reg_save_param保存的函数
本帖最后由 thirfing 于 2013-5-7 16:25 编辑

Problem Description: How to randomly select parameters saved by web_reg_save_param

How to randomly select parameters saved by web_reg_save_param with the attribute ORD = ALL.






--------------------------------------------------------------------------------

Solution: Use custom C coding to randomly select parameters

You can randomly select parameters saved by web_reg_save_param with the attribute ORD = ALL by using custom C coding in your script.

EXAMPLE:

Action1()
{


char* temp,i;
int j;

//create a parameter with the desired boundaries
web_reg_save_param ("pram", "NOTFOUND=ERROR", "LB=left_b","RB=right_b" , "ORD=ALL", LAST );

//call to the URL
web_url("HomePage", "URL=<Your_URL>", LAST);

//get the total number of occurance captured
j = atoi(lr_eval_string("{pram_count}"));

//generate a random number between 1 to j
sprintf(&i, "%d", ( 1 + rand() % j));

//save the random number as a parameter - random_value
lr_save_string(&i, "random_value");

//get the value of parameter x (generated via random number )
temp = lr_eval_string(lr_eval_string("{pram_{random_value}}"));

//save the data as a parameter - random_param
lr_save_string(temp, "random_param");

//call a random URL
web_url("Example", "URL={random_param}", LAST);

return 0;
}
作者: 城邦    时间: 2013-5-8 09:51
抢个沙发先




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2