软件测试工程师应该都知道,在录制脚本过程中,如果脚本中包含需要异步处理的数据,那么LoadRunner会自动扫描是否有需要异步处理的数据,录制完成后会弹出Aysnc设置对话框,在该设置对话框中会显示异步处理的情况。
本章节中以去哪儿官方订票系统为例,如图6-66所示。对异步脚本处理进行介绍,具体步骤如下:
图6-66 飞机票订票系统
1) 选择HTTP/HTML协议录制脚本
注意:异步处理只适用于HTTP/HTML、Flex、Silverlight和Web Services这四种协议。
2) 设置Async Scan选项
进入Recording Options界面,选择General->Code Generation标签页,确定Async Scan复选项是选中状态。
单击Async Options按钮,弹出Asynchronous Request Thresholds对话框,如图6-67所示,在该对话框中可以设置异步请求的参数。
图6-67 Asynchronous Request Thresholds对话框
Minimum Response Size:指定堆异步会话服务器响应的最小字节数,如果服务器发送的字节数小于最小字节数,那么VuGen将不会将这种异步类型归纳为堆的方式。
Maximum Sub Message Size:指定堆异步会话服务器响应的最大字节数,如果服务器发送的字节数大于最大字节数,那么VuGen将不会将这种异步类型归纳为堆的方式。
Minimum Number of Sub Messages:指定堆异步会话发送的最小有效子消息数,如果服务器发送的消息小于子消息数,那么VuGen将不会将这种异步类型归纳为堆的方式。
Interval Tolerance:指定轮询异步的时间间隔时间,单位为毫秒。
Maximum Interval:指定长轮询异步响应结束与发送下一个请求之间的时间间隔。
1) 开始录制脚本
2) 业务录制完成后,停止录制,此时VuGen会自动扫描是否需要异步处理,如果扫描发现有需要异步处理的信息,则会弹出发图6-68所示的信息
图6-68 异步信息
注意:为了VuGen能够成功地确定在异步行为,异步通信必须至少包含所需的最小客户端请求和服务器响应的数量。
1) 单击Close按钮,完成脚本录制,VuGen中产生如下代码
/* Added by Async CodeGen.
ID=Poll_0
ScanType = Recording
The following urls are considered part of this conversation:
http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582390617&_token=72210&deduce=true
http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582391928&_token=19725&deduce=true
http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582395184&_token=24410&deduce=true
TODO - The following callbacks have been added to AsyncCallbacks.c.
Add your code to the callback implementations as necessary.
Poll_0_RequestCB
Poll_0_ResponseBodyBufferCB
Poll_0_ResponseCB
*/
web_reg_async_attributes("ID=Poll_0",
"URL=http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status={CorrelationParameter_3}&_token=72210&deduce=true",
"Pattern=Poll",
"PollIntervalMs=3000",
"RequestCB=Poll_0_RequestCB",
"ResponseBodyBufferCB=Poll_0_ResponseBodyBufferCB",
"ResponseCB=Poll_0_ResponseCB",
LAST);
.
/* Removed by Async CodeGen.
ID = Poll_0
*/
/*
web_url("onewayflight_groupdata.jsp_6",
"URL=http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582391928&_token=19725&deduce=true",
"Resource=1",
"RecContentType=text/plain",
"Referer=http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport=%E6%B7%B1%E5%9C%B3&searchArrivalAirport=%E5%8D%97%E6%98%8C&searchDepartureTime=2013-04-12&searchArrivalTime=2013-04-15&nextNDays=0&startSearch=true&from=qunarindex",
"Snapshot=t167.inf",
LAST);
*/
/* Removed by Async CodeGen.
ID = Poll_0
*/
/*
web_url("onewayflight_groupdata.jsp_7",
"URL=http://flight.qunar.com/twell/flight/tags/onewayflight_groupdata.jsp?&departureCity=%E6%B7%B1%E5%9C%B3&arrivalCity=%E5%8D%97%E6%98%8C&departureDate=2013-04-12&returnDate=2013-04-12&nextNDays=0&searchType=OneWayFlight&searchLangs=zh&locale=zh&from=qunarindex&queryID=192.168.0.19%3A63ab0de2%3A13df30a3fd7%3A-597b&serverIP=l-tw6.f.cn1.qunar.com%2F192.168.0.19&status=1365582395184&_token=24410&deduce=true",
"Resource=1",
"RecContentType=text/plain",
"Referer=http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport=%E6%B7%B1%E5%9C%B3&searchArrivalAirport=%E5%8D%97%E6%98%8C&searchDepartureTime=2013-04-12&searchArrivalTime=2013-04-15&nextNDays=0&startSearch=true&from=qunarindex",
"Snapshot=t168.inf",
LAST);
*/
/* Added by Async CodeGen.
ID = Poll_0
*/
web_stop_async("ID=Poll_0",
LAST);
今天关于“如何使用LoadRunner工具创建异步脚本”的内容就学习完了,大家喜欢的话记得每天来这里和小编一起学习涨薪技能哦。
附:川石信息全国校区最新开班时间,课程资料获取13691729932(微信同号)。