LoadRunner
测试需求:登陆web tours订票网站,预订一张机票后退出
一、Recording录制脚本 1.启动web服务器“Start Web Server” 2.打开“virtual user generator” 3.创建一个新的脚本,选择脚本协议(web(HTTP/HTML)) 4.设置:application type、program to record、URL address、working directory、record into action、record the application startup 5.开始录制,自动打开web tours网页,账号:jojo,密码:bean(注:web页设置为启用隐藏字段标记(Session),所以需要关联) 二、分析脚本 1.web_url详解 函数形式:web_url( const char *StepName, const char *url, , [EXTRARES, ,] LAST );2.web_submit_data详解 函数形式:web_submit_data( const char *StepName, const char *Action, , ITEMDATA, , [ EXTRARES, ,] LAST );
3.脚本实例
Action()
{
web_url("WebTours",//VuGen中树形视图中显示的名称,在自动事务处理中也可以用做事务的名称
"URL=http://127.0.0.1:1080/WebTours/",//页面url地址
"TargetFrame=",//包含当前连接、资源的Frame名称
"Resource=0",//这个URL是否是一个资源,0 表示不是资源,1 表示是资源
"RecContentType=text/html",
//RecContentType:报头文本类型,(text/html,或者 application/x- javascript),确认目标URL是否是可录制的资源
"Referer=",
//Referer:要提交页面请求的URL(获得当前页面,如果明确指出了位置,那么这个属性无效或者忽略。URL中写明了,要获取的页面)
"Snapshot=t1.inf", //Snapshot:快照,快照文件名称,用来关联用
"Mode=HTML", //Mode:录制的等级,分为HTML或者HTTP模式
LAST);//LAST:属性列表结束的标记符
lr_think_time(13);
//是虚拟用户在执行脚本是,停留在那不执行的等待时间,比如说登陆系统后等一段时间后在进行操作
web_submit_data("login.pl", //VuGen中树形视图中显示的名称,在自动事务处理中也可以用作事务的名称
"Action=http://127.0.0.1:1080/WebTours/login.pl",//执行表单提交的URL地址,语法如下:Action=<urlAddress>
"Method=POST", //提交表单的方法,可取值有GET,POST
"TargetFrame=", //包含当前连接、资源的Frame名称
"RecContentType=text/html",//:报头文本类型
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",//要提交该页面请求的URL
"Snapshot=t2.inf",//快照
"Mode=HTML",//录制模式
ITEMDATA, //属性和数据列表的分割标记
"Name=userSession", "Value=121733.628918591zczVzHDpfDHfDHfHApAtVccf", ENDITEM,
"Name=username", "Value=jojo", ENDITEM,
"Name=password", "Value=bean", ENDITEM,
"Name=JSFormSubmit", "Value=on", ENDITEM,
"Name=login.x", "Value=73", ENDITEM,
"Name=login.y", "Value=17", ENDITEM,
LAST);//参数列表结束标志
web_url("Search Flights Button",
"URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
lr_think_time(8);
web_submit_data("reservations.pl",
"Action=http://127.0.0.1:1080/WebTours/reservations.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value=London", ENDITEM,
"Name=departDate", "Value=08/16/2017", ENDITEM,
"Name=arrive", "Value=Los Angeles", ENDITEM,
"Name=returnDate", "Value=08/17/2017", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=.cgifields", "Value=roundtrip", ENDITEM,
"Name=.cgifields", "Value=seatType", ENDITEM,
"Name=.cgifields", "Value=seatPref", ENDITEM,
"Name=findFlights.x", "Value=63", ENDITEM,
"Name=findFlights.y", "Value=11", ENDITEM,
LAST);
web_submit_data("reservations.pl_2",
"Action=http://127.0.0.1:1080/WebTours/reservations.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=outboundFlight", "Value=230;773;08/16/2017", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=reserveFlights.x", "Value=30", ENDITEM,
"Name=reserveFlights.y", "Value=13", ENDITEM,
LAST);
lr_think_time(6);
web_submit_data("reservations.pl_3",
"Action=http://127.0.0.1:1080/WebTours/reservations.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=firstName", "Value=Joseph", ENDITEM,
"Name=lastName", "Value=Marshall", ENDITEM,
"Name=address1", "Value=234 Willow Drive", ENDITEM,
"Name=address2", "Value=San Jose/CA/94085", ENDITEM,
"Name=pass1", "Value=Joseph Marshall", ENDITEM,
"Name=creditCard", "Value=112233", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=oldCCOption", "Value=", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=outboundFlight", "Value=230;773;08/16/2017", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=returnFlight", "Value=", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=.cgifields", "Value=saveCC", ENDITEM,
"Name=buyFlights.x", "Value=83", ENDITEM,
"Name=buyFlights.y", "Value=9", ENDITEM,
LAST);
lr_think_time(8);
web_url("SignOff Button",
"URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);
return 0;
}
三、Replay回放
1.设置“Open Run-Time Settings”
general==》log==》extended log==》全部勾选
2.显示run-time viewer:Tools==>General Options==>show run-time viewer during rep
3.Start Replay
4.有报错,手动关联;又是没有报错,但是replay log 中有报错(红色字)
5.显示结果:View==》Test Result
四、Enhancing the Script内容验证
1.Run-time Settings==>preferences==>勾选enable image and text check
2.Content Checks==》选中内容==》右击==》add a text check
3.脚本内容变化
转载于:.html