loadrunner测试ajax例子

前端之家收集整理的这篇文章主要介绍了loadrunner测试ajax例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

测试的例子:

http://www.degraeve.com/reference/simple-ajax-example.php

如果用WEB(HTTP/HTML)协议来录制,则AJAX行为会被录制成web_submit_data函数

Action()

{

web_add_cookie("__utma=251078419.1213328951.1265334283.1265334283.1265339393.2; DOMAIN=www.degraeve.com");

web_add_cookie("__utmz=251078419.1265334283.1.1.utmccn=(referral)|utmcsr=wilsonmar.com|utmcct=/ajax_rec.htm|utmcmd=referral; DOMAIN=www.degraeve.com");

web_add_cookie("__utmb=251078419; DOMAIN=www.degraeve.com");

web_add_cookie("id=22d81daffc0000c9||t=1264953682|et=730|cs=dyerrpt3; DOMAIN=googleads.g.doubleclick.net");

web_add_cookie("session_2522990=1265121155%260; DOMAIN=c14.statcounter.com");

web_add_cookie("session_1469676=1265339396%260; DOMAIN=c14.statcounter.com");

web_url("simple-ajax-example.PHP",

"URL=http://www.degraeve.com/reference/simple-ajax-example.PHP",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTML",

EXTRARES,

"Url=../css/20061228/headerbg.jpg",ENDITEM,

"Url=http://pagead2.googlesyndication.com/pagead/render_ads.js",

"Url=http://googleads.g.doubleclick.net/pagead/test_domain.js",

"Url=http://pagead2.googlesyndication.com/pagead/expansion_embed.js",

"Url=../css/20061228/external.png",

"Url=http://www.geekchart.com/img/geekchart.swf?username=steve",

"Url=http://www.google-analytics.com/__utm.gif?utmwv=1.3&utmn=1868440947&utmcs=utf-8&utmsr=1280x800&utmsc=32-bit&utmul=zh-cn&utmje=1&utmfl=10.0%20r42&utmdt=Simple%20Ajax%20Example&utmhn=www.degraeve.com&utmhid=1615848864&utmr=-&utmp=/reference/simple-ajax-example.PHP&utmac=UA-427894-1&utmcc=__utma%3D251078419.1213328951.1265334283.1265339393.1265339466.3%3B%2B__utmz%3D251078419.1265334283.1.1.utmccn%3D(referral)%7Cutmcsr%3Dwilsonmar.com%7Cutmcct%3D%2Fajax_rec.htm%7Cutmcmd%3Dreferral%3B%2B",

"Url=http://c14.statcounter.com/t.PHP?sc_project=1469676&resolution=1280&h=800&camefrom=&u=http%3A//www.degraeve.com/reference/simple-ajax-example.PHP&t=Simple%20Ajax%20Example&java=1&security=63fa642a&sc_random=0.49026486354565296&sc_snum=1",

LAST);

web_url("ads",

"URL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-1231725161806454&format=468x60_as&output=html&h=60&w=468&lmt=1265339464&channel=5544617423&ad_type=text_image&alt_color=ffffff&color_bg=FFFFFF&color_border=FFFFFF&color_link=0000FF&color_text=000000&color_url=009900&flash=10.0.42.34&url=http%3A%2F%2Fwww.degraeve.com%2Freference%2Fsimple-ajax-example.PHP&dt=1265339464260&correlator=1265339464291&frm=0&ga_vid=1213328951.1265334283&ga_sid=1265339466&ga_hid=1615848864&ga_fc=1&u_tz=480&"

"u_his=0&u_java=1&u_h=800&u_w=1280&u_ah=772&u_aw=1280&u_cd=32&u_nplug=0&u_nmime=0&biw=1260&bih=643&fu=0&ifi=1&dtd=M&xpc=GJiFPth82m&p=http%3A//www.degraeve.com",

"Referer=http://www.degraeve.com/reference/simple-ajax-example.PHP",

"Snapshot=t2.inf",

LAST);

web_url("api.PHP",

"URL=http://www.geekchart.com/api.PHP?action=getchartdata&username=steve",

"Referer=http://www.geekchart.com/img/geekchart.swf?username=steve",

"Snapshot=t3.inf",

LAST);

web_add_cookie("__utma=251078419.1213328951.1265334283.1265339393.1265339466.3; DOMAIN=www.degraeve.com");

web_add_cookie("__utmc=251078419; DOMAIN=www.degraeve.com");

lr_think_time(37);

web_submit_data("simple-ajax-example.cgi",

"Action=http://www.degraeve.com/cgi-bin/simple-ajax-example.cgi",

"Method=POST",

"RecContentType=text/html",

"Referer=http://www.degraeve.com/reference/simple-ajax-example.PHP",

"Snapshot=t4.inf",

"Mode=HTML",

ITEMDATA,

"Name=w","Value=ajax",

LAST);

return 0;

}

如果用AJAX(Click and Script)协议来录制,则脚本会短很多3个web_url函数被替换成了一个web_browser函数,多个web_add_cookie函数也被一个web_add_cookie_ex函数替代了,ajax行为会被录制成web_edit_field和web_button函数(Click & Script的脚本编写方式更倾向于从用户行为的角度出发,例如在输入框输入、按下按钮等)。

Action()

{

web_add_cookie_ex("Cookie=__utma=251078419.1213328951.1265334283.1265339393.1265339466.3; domain=degraeve.com; path=/",

"Cookie=__utmz=251078419.1265334283.1.1.utmccn=(referral)|utmcsr=wilsonmar.com|utmcct=/ajax_rec.htm|utmcmd=referral; domain=degraeve.com; path=/",

"Cookie=__utmb=251078419; domain=degraeve.com; path=/",

"Cookie=id=22d81daffc0000c9||t=1264953682|et=730|cs=dyerrpt3; domain=doubleclick.net; path=/",

"Cookie=apn-user-id=b4d43f6a-a0d4-4f23-9315-ceb1d859b971; domain=amazon.com; path=/",

LAST);

web_browser("simple-ajax-example.PHP",

DESCRIPTION,

ACTION,

"Navigate=http://www.degraeve.com/reference/simple-ajax-example.PHP",

LAST);

lr_think_time(27);

web_edit_field("word",

"Snapshot=t1.inf",

DESCRIPTION,

"Type=text",

"Name=word",

ACTION,

"SetValue=ajax",

LAST);

web_button("INPUT",

"Snapshot=t2.inf",

"Type=button",

"Tag=INPUT",

"ID=",

"UserAction=Click",

LAST);

return 0;

}

但是,似乎这样录制的HTTP请求内容会少一些,例如对以下URL的请求不能在回放日志中找到:

http://www.geekchart.com/api.php?action=getchartdata&username=steve

在使用WEB(HTTP/HTML)协议来录制时是这行脚本:

web_url("api.PHP",

"Snapshot=t7.inf",

LAST);

原文链接:https://www.f2er.com/ajax/166528.html

猜你在找的Ajax相关文章