性能測試流程
需求調研(性能的測試指標
設計性能測試場景(頻繁使用的功能 核心業務 接口 混合
搭建環境(模擬真實的用戶
開發腳本
檢查點:對結束事務進行判斷,默認結束狀態是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返回的狀態碼,獲取狀態碼值。