51Testing软件测试论坛
标题:
关于loadrunner函数编写位置问题和lr_output_message问题
[打印本页]
作者:
hbacc2047003
时间:
2013-9-9 15:59
标题:
关于loadrunner函数编写位置问题和lr_output_message问题
本帖最后由 hbacc2047003 于 2013-9-9 16:02 编辑
char *randstring(int slen)
{
int i,randid;
char temp[100]="";
char character_set[52]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','a','b','c',
'd','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'};
for(i=1;i<=slen;i++)
{
randid = rand()%52;
sprintf(temp,"%s%c",temp,character_set[randid]);
}
return(temp);
}
Action()
{
web_url("phpwind85",
"URL=http://127.0.0.1:8080/phpwind85",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t3.inf",
"Mode=HTML",
EXTRARES,
"Url=/phpwind85/js/lang/zh_cn.js", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/topbar.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/bg.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/button.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/navA.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/hB.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/searchA.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/down.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/colon.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/select_arrow.gif", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/h.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/new.gif", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/del.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/search_btn.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind8gray/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind8black/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind8green/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind8purple/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/wind85/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/phpwind85/images/register/regright.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
"Url=/favicon.ico", "Referer=", ENDITEM,
"Url=/phpwind85/images/pwicon/top.png", "Referer=http://127.0.0.1:8080/phpwind85/", ENDITEM,
LAST);
lr_think_time(25);
web_submit_data("login.php",
"Action=http://127.0.0.1:8080/phpwind85/login.php",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:8080/phpwind85/",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=jumpurl", "Value=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Name=step", "Value=2", ENDITEM,
"Name=pwuser", "Value={usernameid}", ENDITEM,
"Name=pwpwd", "Value=1234567", ENDITEM,
"Name=head_login", "Value=", ENDITEM,
"Name=lgt", "Value=0", ENDITEM,
EXTRARES,
"Url=images/register/regright2.png", ENDITEM,
"Url=js/lang/zh_cn.js", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/bg.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/topbar.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/g/facebg_a.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/down.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/navA.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/searchA.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/search_btn.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/down.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/colon.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/hB.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/h.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/new.gif", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind8gray/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind8black/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind8green/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind8purple/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/wind85/preview.jpg", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/register/regright.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
"Url=images/pwicon/top.png", "Referer=http://127.0.0.1:8080/phpwind85/index.php", ENDITEM,
LAST);
lr_save_string(randstring(5),"searchstring");
//lr_output_message("zheshi %s",temp[100]);
lr_think_time(10);
lr_start_transaction("search");
web_submit_data("searcher.php",
"Action=http://127.0.0.1:8080/phpwind85/searcher.php",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:8080/phpwind85/index.php",
"Snapshot=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=verify", "Value=b2496deb", ENDITEM,
"Name=step", "Value=2", ENDITEM,
"Name=type", "Value=thread", ENDITEM,
"Name=keyword", "Value={searchstring}", ENDITEM,
EXTRARES,
"Url=images/search/search_del.png", ENDITEM,
"Url=images/search/search_btn.png", ENDITEM,
"Url=images/search/pImg.png", ENDITEM,
"Url=u/images/pre.cur", ENDITEM,
"Url=u/images/next.cur", ENDITEM,
"Url=images/search/pImg_close.png", ENDITEM,
LAST);
lr_end_transaction("search", LR_AUTO);
return 0;
}
复制代码
有这么几个问题,希望达人解答下
1.如果上述代码所述,函数randstring写在action外面是能完全走完脚本的,但是为什么写在action里面就各种报错了呢?错误信息不截图了,太多了
2.如102行代码所示,我想输出一个值,查看随机出的字符串。但是只要加上这行代码,会提示我以下信息
Action.c (14): warning: pointer to local `temp' is an illegal return value
Action.c (102): undeclared identifier `temp'
Action.c (102): type error: pointer expected
e:\\phpwind\301\252\317\265\275\305\261\276\\\277\264\314\373\\\\combined_\277\264\314\373.c (5): 2 errors, not writing pre_cci.ci
作者:
云层
时间:
2013-9-9 18:08
这个问题我貌似在blog上写过,在我当初写这个例子的LR版本上从函数返回的数据可以走入action中并被转化为参数,但是后面有人问到这个问题,我也出现了该问题,于是就修改了代码,你在函数中直接转化为参数来做就不会有错了,具体问题为什么,确实一下不知道原因。
作者:
云层
时间:
2013-9-9 18:09
参考这个
http://www.51testing.com/index.p ... space-itemid-847266
作者:
hbacc2047003
时间:
2013-9-10 08:55
回复
3#
云层
谢谢,参考下
作者:
hbacc2047003
时间:
2013-9-10 12:28
回复
3#
云层
自己查找了下,P349上面的randstring函数本身写的好像有些问题?
我的理解是:
randstring因为返回的是一个指针,当这个函数执行完毕后,内存空间清空了,所以在action里面怎么也取不到值
我试下来正确的写法是(只写有变动的地方)
int randstring(char* temp,int slen)
{
//char temp[100] = "";
return 0 ;
}
action
{
char *p;
p=(char*)malloc(100);
randstring(p,5);
lr_save_string(p,“search”);
}
通过主函数里面定义的P指针,在主函数中开辟一个内存空间,让temp指针指向P指针的内容,这样内存清空后,P还是能拿到值
作者:
云层
时间:
2013-9-10 13:27
回复 云层
自己查找了下,P349上面的randstring函数本身写的好像有些问题?
我的理解是:
...
hbacc2047003 发表于 2013-9-10 12:28
多谢指导
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2