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", ENDITEM,

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

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

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

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

              "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", ENDITEM,

              "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", ENDITEM,

 

              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",

              "Resource=0",

              "RecContentType=text/html",

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

              "Snapshot=t2.inf",

              "Mode=HTML",

              LAST);

 

       web_url("api.php",

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

              "Resource=0",

              "RecContentType=text/html",

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

              "Snapshot=t3.inf",

              "Mode=HTML",

              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", ENDITEM,

              LAST);

 

       return 0;

}

 

 

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

 

Action()

{

 

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

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

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

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

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

              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",

              DESCRIPTION,

              "Type=button",

              "Tag=INPUT",

              "ID=",

              ACTION,

              "UserAction=Click",

              LAST);

 

       return 0;

}

 

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

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

 

 

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

       web_url("api.php",

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

              "Resource=0",

              "RecContentType=text/html",

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

              "Snapshot=t7.inf",

              "Mode=HTML",

              LAST);

 

你可能感兴趣的:(Ajax,Web,测试,url,domain,loadrunner)