LoadRunner脚本编写
性能测试流程
需求调研(性能的测试指标
设计性能测试场景(频繁使用的功能 核心业务 接口 混合
搭建环境(模拟真实的用户
开发脚本
检查点:对结束事务进行判断,默认结束状态是LR_AUTO
参数化:模拟真实用户使用
关联:服务器返回的动态参数
集合点:做并发测试
场景设计:单业务开发。核心业务并发、第三方接口、混合场景,监控服务器资源(cpu.内存,磁盘网络)
执行场景:发现问题,挑有
性能测试报告
一.脚本编写
案例一(登录注册手写脚本)
Action() { //请求1 web_custom_request("WebTours", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t1.inf", //录制快照保存到t1.inf中 "Mode=HTTP", //录制的模式HTTP LAST); //请求2 web_custom_request("header.html", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/header.html", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t2.inf", //录制快照保存到t2.inf中 "Mode=HTTP", //录制的模式HTTP LAST); //请求3 web_custom_request("signOff=true", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t3.inf", //录制快照保存到t3.inf中 "Mode=HTTP", //录制的模式HTTP LAST); //关联函数 web_reg_save_param_ex("Paramname=userSession", "LB=name=userSession value=", "RB=>", LAST); //请求4 web_custom_request("in=home", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //Get请求的地址 "Method=POST", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t4.inf", //录制快照保存到t4.inf中 "Mode=HTTP", //录制的模式HTTP LAST); //请求5 web_custom_request("home.html", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/home.html", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t5.inf", //录制快照保存到t5.inf中 "Mode=HTTP", //录制的模式HTTP LAST); lr_start_transaction("登录"); //POST web_custom_request("login.pl", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/login.pl", //Get请求的地址 "Method=POST", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //请求的页面,在URL写明后,该属性无效可省略 "Snapshot=t6.inf", //录制快照保存到t6.inf中 "Mode=HTTP", //录制的模式HTTP "Body=userSession={userSession}&username=test001&password=123456", LAST); //请求7 web_custom_request("in=home", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t7.inf", //录制快照保存到t7.inf中 "Mode=HTTP", //录制的模式HTTP LAST); //检查点 web_reg_find("Text=Welcome, <b>test001</b>,", "Savecount=登录计数", LAST); //请求8 web_custom_request("tro=true", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t8.inf", //录制快照保存到t8.inf中 "Mode=HTTP", //录制的模式HTTP LAST);
//判断登录成功与否 if(atoi(lr_eval_string("{登录计数}")) >0){ lr_end_transaction("登录", LR_PASS); }else{ lr_end_transaction("登录", LR_FAIL); } //请求9 web_custom_request("signOff=1", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t9.inf", //录制快照保存到t9.inf中 "Mode=HTTP", //录制的模式HTTP LAST); //请求10 web_custom_request("in=home", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t10.inf", //录制快照保存到t10.inf中 "Mode=HTTP", //录制的模式HTTP LAST);
//请求11 web_custom_request("home.html", //可以自定义 "URL=http://127.0.0.1:1080/WebTours/home.html", //Get请求的地址 "Method=GET", //方式GET "Resource=0", //说明URL是否是一个资源,0代表不是资源,1代表是资源 "RecContentType=text/html", //录制时响应报头文本类型 "Snapshot=t11.inf", //录制快照保存到t11.inf中 "Mode=HTTP", //录制的模式HTTP LAST); return 0; }
案例二(登录注册手写脚本使用web_custom_request)
Action() { //请求1 web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t1.inf", "Mode=HTTP", LAST ); //请求2 web_url("header.html", "URL=http://127.0.0.1:1080/WebTours/header.html", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t2.inf", "Mode=HTTP", LAST );
//请求3 web_url("welcome.pl?signOff=true", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t3.inf", "Mode=HTTP", LAST ); //插入关联函数<input type=hidden name=userSession value=119191.457108141zVDAQVApfHfDzHifptzDtf> web_reg_save_param_ex("Paramname=userSession", "LB=name=userSession value=", "RB=>", LAST);
//请求4 web_url("in=home", "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t4.inf", "Mode=HTTP", LAST ); //请求5 web_url("home.html", "URL=http://127.0.0.1:1080/WebTours/home.html", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t5.inf", "Mode=HTTP", LAST ); lr_start_transaction("登录"); //post提交
web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t6.inf", "Mode=HTTP", ITEMDATA, "Name=username", "Value=test001", ENDITEM, "Name=password", "Value=123456", ENDITEM, "Name=userSession", "Value={userSession}", ENDITEM, LAST );
//请求7 web_url("nav.pl?page=menu&in=home", "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t7.inf", "Mode=HTTP", LAST ); //检查点 Welcome, <b>test001</b>, web_reg_find("Text=Welcome, <b>test001</b>,", "Savecount=登录计数", LAST); //请求8 web_url("login.pl?intro=true", "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t8.inf", "Mode=HTTP", LAST );
//判断登录成功与否 if(atoi(lr_eval_string("{登录计数}")) >0){ lr_end_transaction("登录", LR_PASS); }else{ lr_end_transaction("登录", LR_FAIL); } //lr_end_transaction("登录", LR_AUTO); //请求9 web_url("welcome.pl?signOff=1", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t9.inf", "Mode=HTTP", LAST ); //请求10 web_url("nav.pl?in=home", "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t10.inf", "Mode=HTTP", LAST ); //请求11 web_url("home.html", "URL=http://127.0.0.1:1080/WebTours/home.html", //"TargetFrame=", //"TargetBrowser=Mercury Technologies", "Resource=0", "RecContentType=text/html", "Snapshot=t11.inf", "Mode=HTTP", LAST ); return 0; }
案例三(随机订票方法一——选项固定)
Action() { web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTTP", LAST); web_url("header.html", "URL=http://127.0.0.1:1080/WebTours/header.html", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t2.inf", "Mode=HTTP", LAST); web_url("welcome.pl", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t5.inf", "Mode=HTTP", LAST); web_url("home.html", "URL=http://127.0.0.1:1080/WebTours/home.html", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "Snapshot=t6.inf", "Mode=HTTP", LAST); //关联usersession web_reg_save_param_ex( "ParamName=usersession", "LB=userSession value=", "RB=>\n<table border", SEARCH_FILTERS, "Scope=All", LAST); web_url("nav.pl", "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "Snapshot=t7.inf", "Mode=HTTP", LAST); lr_start_transaction("登录"); web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t9.inf", "Mode=HTTP", ITEMDATA, "Name=userSession", "Value={usersession}", ENDITEM, "Name=username", "Value=test002", ENDITEM, "Name=password", "Value=123456", ENDITEM, "Name=JSFormSubmit", "Value=off", ENDITEM, "Name=login.x", "Value=53", ENDITEM, "Name=login.y", "Value=11", ENDITEM, LAST); web_url("nav.pl_2", "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/login.pl", "Snapshot=t10.inf", "Mode=HTTP", LAST); web_reg_find("Text=Welcome, <b>test002</b>, ", "Fail=NotFound", "SaveCount=登录次数", "Search=Body", LAST); web_url("login.pl_2", "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/login.pl", "Snapshot=t14.inf", "Mode=HTTP", LAST); if(atoi(lr_eval_string("{登录次数}")) >0){ lr_end_transaction("登录", LR_PASS); }else{ lr_end_transaction("登录", LR_FAIL); }; lr_start_transaction("订票"); lr_think_time(12); //关联地址 web_reg_save_param_ex( "ParamName=目的地", "LB=option value=\"", "RB=\">", "Ordinal={randomnumber}", SEARCH_FILTERS, "Scope=All", LAST); lr_output_message("目的地的值是: ",lr_eval_string("目的地")); web_url("reservations.pl", "URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", "Snapshot=t17.inf", "Mode=HTTP", LAST); web_url("Search Flights Button", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", "Snapshot=t16.inf", "Mode=HTTP", LAST); web_url("nav.pl_3", "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", "Snapshot=t18.inf", "Mode=HTTP", LAST); web_submit_data("reservations.pl_2", "Action=http://127.0.0.1:1080/WebTours/reservations.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", "Snapshot=t22.inf", "Mode=HTTP", ITEMDATA, "Name=advanceDiscount", "Value=0", ENDITEM, "Name=depart", "Value=Denver", ENDITEM, "Name=departDate", "Value=08/20/2016", ENDITEM, "Name=arrive", "Value={目的地}", ENDITEM, "Name=returnDate", "Value=08/21/2016", 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=55", ENDITEM, "Name=findFlights.y", "Value=5", ENDITEM, LAST); web_submit_data("reservations.pl_3", "Action=http://127.0.0.1:1080/WebTours/reservations.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", "Snapshot=t24.inf", "Mode=HTTP", ITEMDATA, "Name=outboundFlight", "Value=031;224;08/20/2016", 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=75", ENDITEM, "Name=reserveFlights.y", "Value=4", ENDITEM, LAST); web_submit_data("reservations.pl_4", "Action=http://127.0.0.1:1080/WebTours/reservations.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", "Snapshot=t25.inf", "Mode=HTTP", ITEMDATA, "Name=firstName", "Value=m", ENDITEM, "Name=lastName", "Value=m", ENDITEM, "Name=address1", "Value=m", ENDITEM, "Name=address2", "Value=m", ENDITEM, "Name=pass1", "Value=m m", ENDITEM, "Name=creditCard", "Value=", 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=031;224;08/20/2016", ENDITEM, "Name=advanceDiscount", "Value=0", ENDITEM, "Name=returnFlight", "Value=", ENDITEM, "Name=JSFormSubmit", "Value=off", ENDITEM, "Name=.cgifields", "Value=saveCC", ENDITEM, "Name=buyFlights.x", "Value=42", ENDITEM, "Name=buyFlights.y", "Value=16", ENDITEM, LAST); lr_end_transaction("订票", LR_AUTO); lr_start_transaction("退出"); web_url("welcome.pl_2", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", "Snapshot=t27.inf", "Mode=HTTP", LAST); web_url("home.html_2", "URL=http://127.0.0.1:1080/WebTours/home.html", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "Snapshot=t28.inf", "Mode=HTTP", LAST); web_url("nav.pl_4", "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "Snapshot=t29.inf", "Mode=HTTP", LAST); lr_end_transaction("退出", LR_AUTO); return 0; }
案例四(随机订票方法二——选项固定)
Action() { int num; char str1[20]; web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTTP", LAST); web_url("header.html", "URL=http://127.0.0.1:1080/WebTours/header.html", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t2.inf", "Mode=HTTP", LAST); web_url("welcome.pl", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t5.inf", "Mode=HTTP", LAST); web_url("home.html", "URL=http://127.0.0.1:1080/WebTours/home.html", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "Snapshot=t6.inf", "Mode=HTTP", LAST); //关联usersession web_reg_save_param_ex( "ParamName=usersession", "LB=userSession value=", "RB=>\n<table border", SEARCH_FILTERS, "Scope=All", LAST); web_url("nav.pl", "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "Snapshot=t7.inf", "Mode=HTTP", LAST); lr_start_transaction("登录"); web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t9.inf", "Mode=HTTP", ITEMDATA, "Name=userSession", "Value={usersession}", ENDITEM, "Name=username", "Value=test002", ENDITEM, "Name=password", "Value=123456", ENDITEM, "Name=JSFormSubmit", "Value=off", ENDITEM, "Name=login.x", "Value=53", ENDITEM, "Name=login.y", "Value=11", ENDITEM, LAST); web_url("nav.pl_2", "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/login.pl", "Snapshot=t10.inf", "Mode=HTTP", LAST); web_reg_find("Text=Welcome, <b>test002</b>, ", "Fail=NotFound", "SaveCount=登录次数", "Search=Body", LAST); web_url("login.pl_2", "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/login.pl", "Snapshot=t14.inf", "Mode=HTTP", LAST); if(atoi(lr_eval_string("{登录次数}")) >0){ lr_end_transaction("登录", LR_PASS); }else{ lr_end_transaction("登录", LR_FAIL); }; lr_start_transaction("订票"); //关联地址 web_reg_save_param_ex( "ParamName=所有目的地", "LB=option value=\"", "RB=\">", "Ordinal=ALL", SEARCH_FILTERS, "Scope=All", LAST); lr_output_message("--------目的地的值为:%s",lr_eval_string("{目的地}")); web_url("reservations.pl", "URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", "Snapshot=t17.inf", "Mode=HTTP", LAST); web_url("Search Flights Button", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", "Snapshot=t16.inf", "Mode=HTTP", LAST); web_url("nav.pl_3", "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", "Snapshot=t18.inf", "Mode=HTTP", LAST); num=rand()%9 + 10; sprintf(str1,"{所有目的地_%d}",num);//拼接字符 因为地址是参数所以用{} lr_save_string(lr_eval_string(str1),"目的地");//赋值 lr_think_time(7); web_submit_data("reservations.pl_2", "Action=http://127.0.0.1:1080/WebTours/reservations.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", "Snapshot=t22.inf", "Mode=HTTP", ITEMDATA, "Name=advanceDiscount", "Value=0", ENDITEM, "Name=depart", "Value=Denver", ENDITEM, "Name=departDate", "Value=08/20/2016", ENDITEM, "Name=arrive", "Value={目的地}", ENDITEM, "Name=returnDate", "Value=08/21/2016", 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=55", ENDITEM, "Name=findFlights.y", "Value=5", ENDITEM, LAST); //lr_output_message("------arrive的值为:%s",lr_eval_string("arrive")); lr_think_time(12); web_submit_data("reservations.pl_3", "Action=http://127.0.0.1:1080/WebTours/reservations.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", "Snapshot=t24.inf", "Mode=HTTP", ITEMDATA, "Name=outboundFlight", "Value=031;224;08/20/2016", 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=75", ENDITEM, "Name=reserveFlights.y", "Value=4", ENDITEM, LAST); web_submit_data("reservations.pl_4", "Action=http://127.0.0.1:1080/WebTours/reservations.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", "Snapshot=t25.inf", "Mode=HTTP", ITEMDATA, "Name=firstName", "Value=m", ENDITEM, "Name=lastName", "Value=m", ENDITEM, "Name=address1", "Value=m", ENDITEM, "Name=address2", "Value=m", ENDITEM, "Name=pass1", "Value=m m", ENDITEM, "Name=creditCard", "Value=", 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=031;224;08/20/2016", ENDITEM, "Name=advanceDiscount", "Value=0", ENDITEM, "Name=returnFlight", "Value=", ENDITEM, "Name=JSFormSubmit", "Value=off", ENDITEM, "Name=.cgifields", "Value=saveCC", ENDITEM, "Name=buyFlights.x", "Value=42", ENDITEM, "Name=buyFlights.y", "Value=16", ENDITEM, LAST); lr_end_transaction("订票", LR_AUTO); lr_start_transaction("退出"); lr_think_time(11); web_url("welcome.pl_2", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", "Snapshot=t27.inf", "Mode=HTTP", LAST); web_url("home.html_2", "URL=http://127.0.0.1:1080/WebTours/home.html", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "Snapshot=t28.inf", "Mode=HTTP", LAST); web_url("nav.pl_4", "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "Snapshot=t29.inf", "Mode=HTTP", LAST); lr_end_transaction("退出", LR_AUTO); return 0; }
案例五 (选项随机化——使用指针)
1 Action() 2 { 3 char *fly; 4 5 web_url("WebTours", 6 "URL=http://127.0.0.1:1080/WebTours/", 7 "Resource=0", 8 "RecContentType=text/html", 9 "Referer=", 10 "Snapshot=t1.inf", 11 "Mode=HTTP", 12 LAST); 13 14 15 web_url("header.html", 16 "URL=http://127.0.0.1:1080/WebTours/header.html", 17 "Resource=0", 18 "RecContentType=text/html", 19 "Referer=http://127.0.0.1:1080/WebTours/", 20 "Snapshot=t2.inf", 21 "Mode=HTTP", 22 LAST); 23 24 web_url("welcome.pl", 25 "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", 26 "Resource=0", 27 "RecContentType=text/html", 28 "Referer=http://127.0.0.1:1080/WebTours/", 29 "Snapshot=t5.inf", 30 "Mode=HTTP", 31 LAST); 32 33 web_url("home.html", 34 "URL=http://127.0.0.1:1080/WebTours/home.html", 35 "Resource=0", 36 "RecContentType=text/html", 37 "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", 38 "Snapshot=t6.inf", 39 "Mode=HTTP", 40 LAST); 41 42 //Correlation comment - Do not change!Original value='119204.148643175zVDVfzDpDQfiDDDDDzHiQpDiADHf' Name ='CorrelationParameter_1' 43 web_reg_save_param_ex( 44 "ParamName=usersession", 45 "LB=userSession value=", 46 "RB=>\n<table border", 47 SEARCH_FILTERS, 48 "Scope=All", 49 LAST); 50 web_url("nav.pl", 51 "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 52 "Resource=0", 53 "RecContentType=text/html", 54 "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", 55 "Snapshot=t7.inf", 56 "Mode=HTTP", 57 LAST); 58 59 60 61 62 lr_rendezvous("登录集合点"); 63 64 lr_start_transaction("登录"); 65 66 lr_think_time(15); 67 68 web_submit_data("login.pl", 69 "Action=http://127.0.0.1:1080/WebTours/login.pl", 70 "Method=POST", 71 "RecContentType=text/html", 72 "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 73 "Snapshot=t9.inf", 74 "Mode=HTTP", 75 ITEMDATA, 76 "Name=userSession", "Value={usersession}", ENDITEM, 77 "Name=username", "Value={username}", ENDITEM, 78 "Name=password", "Value=123456", ENDITEM, 79 "Name=JSFormSubmit", "Value=off", ENDITEM, 80 "Name=login.x", "Value=53", ENDITEM, 81 "Name=login.y", "Value=11", ENDITEM, 82 LAST); 83 84 85 web_url("nav.pl_2", 86 "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", 87 "Resource=0", 88 "RecContentType=text/html", 89 "Referer=http://127.0.0.1:1080/WebTours/login.pl", 90 "Snapshot=t10.inf", 91 "Mode=HTTP", 92 LAST); 93 94 web_reg_find("Text=Welcome, <b>{username}</b>, ", 95 "Fail=NotFound", 96 "SaveCount=登录次数", 97 "Search=Body", 98 LAST); 99 web_url("login.pl_2", 100 "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true", 101 "Resource=0", 102 "RecContentType=text/html", 103 "Referer=http://127.0.0.1:1080/WebTours/login.pl", 104 "Snapshot=t14.inf", 105 "Mode=HTTP", 106 LAST); 107 108 if(atoi(lr_eval_string("{登录次数}")) >0){ 109 lr_end_transaction("登录", LR_PASS); 110 }else{ 111 lr_end_transaction("登录", LR_FAIL); 112 }; 113 114 lr_start_transaction("订票"); 115 116 lr_think_time(12); 117 118 119 120 //Correlation comment - Do not change!Original value='London' Name ='CorrelationParameter_1' 121 web_reg_save_param_ex( 122 "ParamName=目的地", 123 "LB=option value=\"", 124 "RB=\">", 125 "Ordinal={randomnumber}", 126 SEARCH_FILTERS, 127 "Scope=All", 128 LAST); 129 130 web_url("reservations.pl", 131 "URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", 132 "Resource=0", 133 "RecContentType=text/html", 134 "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", 135 "Snapshot=t17.inf", 136 "Mode=HTTP", 137 LAST); 138 139 web_url("Search Flights Button", 140 "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", 141 "Resource=0", 142 "RecContentType=text/html", 143 "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", 144 "Snapshot=t16.inf", 145 "Mode=HTTP", 146 LAST); 147 web_url("nav.pl_3", 148 "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", 149 "Resource=0", 150 "RecContentType=text/html", 151 "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", 152 "Snapshot=t18.inf", 153 "Mode=HTTP", 154 LAST); 155 156 lr_think_time(7); 157 lr_output_message("目的地的值是: ", lr_eval_string("目的地")); 158 159 //Correlation comment - Do not change!Original value='040;350;08/20/2016' Name ='CorrelationParameter_1' 160 161 web_reg_save_param_ex( 162 "ParamName=所有航班星系", 163 "LB=outboundFlight value=", 164 "RB=08/20/2016", 165 "Ordinal=all", 166 SEARCH_FILTERS, 167 "Scope=All", 168 LAST); 169 170 web_submit_data("reservations.pl_2", 171 "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 172 "Method=POST", 173 "RecContentType=text/html", 174 "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", 175 "Snapshot=t22.inf", 176 "Mode=HTTP", 177 ITEMDATA, 178 "Name=advanceDiscount", "Value=0", ENDITEM, 179 "Name=depart", "Value=Denver", ENDITEM, 180 "Name=departDate", "Value=08/20/2016", ENDITEM, 181 "Name=arrive", "Value={目的地}", ENDITEM, 182 "Name=returnDate", "Value=08/21/2016", ENDITEM, 183 "Name=numPassengers", "Value=1", ENDITEM, 184 "Name=seatPref", "Value=None", ENDITEM, 185 "Name=seatType", "Value=Coach", ENDITEM, 186 "Name=.cgifields", "Value=roundtrip", ENDITEM, 187 "Name=.cgifields", "Value=seatType", ENDITEM, 188 "Name=.cgifields", "Value=seatPref", ENDITEM, 189 "Name=findFlights.x", "Value=55", ENDITEM, 190 "Name=findFlights.y", "Value=5", ENDITEM, 191 LAST); 192 193 194 lr_think_time(12); 195 fly=lr_paramarr_random("所有航班星系"); 196 lr_save_string(fly,"航班信息"); 197 lr_output_message("航班信息是:","{航班信息}"); 198 199 web_submit_data("reservations.pl_3", 200 "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 201 "Method=POST", 202 "RecContentType=text/html", 203 "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 204 "Snapshot=t24.inf", 205 "Mode=HTTP", 206 ITEMDATA, 207 "Name=outboundFlight", "Value=031;224;08/20/2016", ENDITEM, 208 "Name=numPassengers", "Value=1", ENDITEM, 209 "Name=advanceDiscount", "Value=0", ENDITEM, 210 "Name=seatType", "Value=Coach", ENDITEM, 211 "Name=seatPref", "Value=None", ENDITEM, 212 "Name=reserveFlights.x", "Value=75", ENDITEM, 213 "Name=reserveFlights.y", "Value=4", ENDITEM, 214 LAST); 215 216 web_submit_data("reservations.pl_4", 217 "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 218 "Method=POST", 219 "RecContentType=text/html", 220 "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 221 "Snapshot=t25.inf", 222 "Mode=HTTP", 223 ITEMDATA, 224 "Name=firstName", "Value=m", ENDITEM, 225 "Name=lastName", "Value=m", ENDITEM, 226 "Name=address1", "Value=m", ENDITEM, 227 "Name=address2", "Value=m", ENDITEM, 228 "Name=pass1", "Value=m m", ENDITEM, 229 "Name=creditCard", "Value=", ENDITEM, 230 "Name=expDate", "Value=", ENDITEM, 231 "Name=oldCCOption", "Value=", ENDITEM, 232 "Name=numPassengers", "Value=1", ENDITEM, 233 "Name=seatType", "Value=Coach", ENDITEM, 234 "Name=seatPref", "Value=None", ENDITEM, 235 "Name=outboundFlight", "Value=031;224;08/20/2016", ENDITEM, 236 "Name=advanceDiscount", "Value=0", ENDITEM, 237 "Name=returnFlight", "Value=", ENDITEM, 238 "Name=JSFormSubmit", "Value=off", ENDITEM, 239 "Name=.cgifields", "Value=saveCC", ENDITEM, 240 "Name=buyFlights.x", "Value=42", ENDITEM, 241 "Name=buyFlights.y", "Value=16", ENDITEM, 242 LAST); 243 244 245 246 lr_end_transaction("订票", LR_AUTO); 247 248 lr_start_transaction("退出"); 249 250 lr_think_time(11); 251 252 web_url("welcome.pl_2", 253 "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", 254 "Resource=0", 255 "RecContentType=text/html", 256 "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", 257 "Snapshot=t27.inf", 258 "Mode=HTTP", 259 LAST); 260 261 262 web_url("home.html_2", 263 "URL=http://127.0.0.1:1080/WebTours/home.html", 264 "Resource=0", 265 "RecContentType=text/html", 266 "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", 267 "Snapshot=t28.inf", 268 "Mode=HTTP", 269 LAST); 270 271 web_url("nav.pl_4", 272 "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 273 "Resource=0", 274 "RecContentType=text/html", 275 "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", 276 "Snapshot=t29.inf", 277 "Mode=HTTP", 278 LAST); 279 280 281 lr_end_transaction("退出", LR_AUTO); 282 283 return 0; 284 }
案例六 (选项随机化——使用字符串)
//与案例五中使用指针的方法不同,这用的是字符数组存储变量 int num; char str1[20];//用来存储取出的值 num=rand()%9 + 10;//随机产生0-8的数字,加10后则随机产生10-18的数字 sprintf( str1,"{所有目的地_%d}",num );//拼接字符, lr_save_string( lr_eval_string(str1),"目的地" );//变量不能直接使用必须用函数存储
二.登录脚本编写流程及注意事项
1.流程
编写方式:录制和手写(下面记录手写方式)
需要工具:httpwatch 或者是 fiddler
具体流程:
执行一次登录,将请求通过抓包工具记录下来
筛选请求:如果没有特别要求,图片等格式需求可以忽略
将get请求写入脚本
将post请求写入脚本
寻找检查点——登录成功的网页>查看源码>复制成功登录判断点
插入检查点函数——放到请求登录成功网页的前面()
web_reg_find("Text=Welcome, <b>test001</b>,", "Savecount=登录计数", LAST);
插入关联函数从服务器获得的动态参数
位置:放在第一次出现session值的网页前
web_reg_save_param_ex("Paramname=userSession", "LB=name=userSession value=", "RB=>", LAST);
添加if语句判断事务是否成功
(必须先有一个开始事物
(将结束事物替换为判断条件
if(atoi(lr_eval_string("{登录计数}")) >0){ lr_end_transaction("登录", LR_PASS); }else{ lr_end_transaction("登录", LR_FAIL); }
2.注意事项
参数列表中设置选项选择312——唯一值,每次迭代更新
三.执行
工具——〉创建controler场景 如果出现错误检查是否注册码失效,或者用管理员运行LR
开启windows服务 ——〉services.msc——〉Remote Registry改为手动,然后启动
场景——〉集合(没有亮的话,回脚本界面 插入——〉集合 ,场景界面点击路径再重加载脚本 )
运行——〉可用图——〉windonws资源图——〉右键添加度量——〉添加——〉输入自己电脑的ip
四.分析结果
未完待续。。
备注:
web_get_int_property(HTTP_INFO_RETURN_CODE); // HTTP_INFO_RETURN_CODE : HTTP返回的状态码,获取状态码值。