loadrunner ajax,使用loadrunner11的AJAX,WEB协议录制百度搜索脚本

使用loadrunner11的AJAX,WEB协议录制百度搜索脚本

2011-07-12  张洪杰

最近看到一个帖子是讨论有关使用loadrunner录制百度搜索脚本,说利用百度搜时使用了AJAX技术,所有在录制的时候遇到小问题,因为好奇也抽空练习了下。用的工具是loadrunner11,分别采用了web协议和AJAX协议对脚本进行了录制,比较如下:

1.web协议

1)首先设置采用url方式进行录制脚本

2)设计场景:打开百度>输入:loadrunner>随机点击搜索list的某值

3)优化脚本

用web_reg_save_param 函数获取搜索list的所有值

用lr_paramarr_random 函数随机获取list值

用lr_save_string 函数把随机的list值保存在临时变量tmp

参数化4)最后脚本

Action()

{

//char *tmp[100];

web_add_cookie("BAIDUID=6E2658B7F8D582D7EBD5C2978E6B9A2E:FG=1; DOMAIN=www.baidu.com");

web_url("www.baidu.com",

"URL=http://www.baidu.com/",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTTP",

LAST);

web_url("baidu_sylogo1.gif",

"URL=http://www.baidu.com/img/baidu_sylogo1.gif",

"Resource=1",

"RecContentType=image/gif",

"Referer=http://www.baidu.com/",

"Snapshot=t2.inf",

LAST);

web_url("gs.gif",

"URL=http://gimg.baidu.com/img/gs.gif",

"Resource=1",

"RecContentType=image/gif",

"Referer=http://www.baidu.com/",

"Snapshot=t5.inf",

LAST);

web_url("i2.png",

"URL=http://www.baidu.com/img/i2.png",

"Resource=1",

"RecContentType=image/png",

"Referer=http://www.baidu.com/",

"Snapshot=t3.inf",

LAST);

web_url("arr.gif",

"URL=http://www.baidu.com/img/arr.gif",

"Resource=1",

"RecContentType=image/gif",

"Referer=http://www.baidu.com/",

"Snapshot=t4.inf",

LAST);

web_url("hps-1.1.js",

"URL=http://www.baidu.com/cache/hps/js/hps-1.1.js",

"Resource=1",

"RecContentType=application/javascript",

"Referer=http://www.baidu.com/",

"Snapshot=t6.inf",

LAST);

web_url("bdsug.js",

"URL=http://www.baidu.com/js/bdsug.js?v=1.0.3.0",

"Resource=1",

"RecContentType=application/javascript",

"Referer=http://www.baidu.com/",

"Snapshot=t7.inf",

LAST);

web_url("favicon.ico",

"URL=http://www.baidu.com/favicon.ico",

"Resource=1",

"RecContentType=image/x-icon",

"Referer=",

"Snapshot=t8.inf",

LAST);

web_reg_save_param("SearchID",

"LB=\"",

"RB=\",",

"Ord=all",

"Search=body",

LAST);

//lr_save_var();

web_url("su_10",

"URL=http://suggestion.baidu.com/su?wd={keyword}&p=3&cb=window.bdsug.sug&t=1310455791339",

"Resource=1",

"RecContentType=baiduapp/json",

"Referer=http://www.baidu.com/",

"Snapshot=t18.inf",

LAST);

//lr_save_string(lr_paramarr_random("SearchID"),*tmp);

lr_save_string(lr_paramarr_random("SearchID"),"tmp");

//lr_output_message("title is :%s",lr_paramarr_random("SearchID"));

//lr_output_message("title is :%s",tmp);

//web_concurrent_end(NULL);

lr_think_time(12);

web_url("s",

"URL=http://www.baidu.com/s?wd={tmp}&rsp=4&f=3&inputT=6478",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/",

"Snapshot=t19.inf",

"Mode=HTTP",

LAST);

return 0;

}

2.AJAX协议

相比web的脚本,AJAX协议脚本更简单易读,具体如下:

Action()

{

web_add_cookie_ex("Cookie=BAIDUID=6E2658B7F8D582D7EBD5C2978E6B9A2E:FG=1; domain=baidu.com; path=/", ENDITEM,

LAST);

web_browser("www.baidu.com",

DESCRIPTION,

ACTION,

"Navigate=http://www.baidu.com/",

LAST);

web_edit_field("wd",

"Snapshot=t1.inf",

DESCRIPTION,

"Type=text",

"Name=wd",

ACTION,

"FireEvent=onfocus",

LAST);

web_edit_field("wd_2",

"Snapshot=t3.inf",

DESCRIPTION,

"Type=text",

"Name=wd",

ACTION,

"SetValue=loadrunner",

LAST);

web_reg_find("Text=loadrunner","SaveCount=count1",LAST);

web_button("INPUT",

"Snapshot=t4.inf",

DESCRIPTION,

"Type=submit",

"Tag=INPUT",

"ID=su",

ACTION,

"UserAction=Click",

LAST);

return 0;

}

0

该文章对我有帮助

809°|8087 人阅读|1

条评论

d03abb11e5bfb9865c2bcc0d88742915.png

小窝  2011-07-14

同步至官方微博

请 登录 后发表评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值