Loadrunner自带webtours的完整脚本
Posted 转圈又是原点
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Loadrunner自带webtours的完整脚本相关的知识,希望对你有一定的参考价值。
该脚本涉及webtours的注册、登录、预定、取消、退出操作,编写的过程使用不录制的方式,根据get、post确定方法。
1 /*----------------- vuser_init -----------------*/ 2 vuser_init() 3 { 4 return 0; 5 } 6 /*----------------- sign -----------------*/ 7 sign() 8 { 9 lr_start_transaction("sign_hp"); 10 11 web_url("sign_hp","url=http://127.0.0.1:1080/WebTours/login.pl?username=&password=&getInfo=true",LAST); 12 13 lr_end_transaction("sign_hp",LR_AUTO); 14 15 16 web_reg_save_param("sign_on","LB=<title>","RB=</title>","Search=body","notfound=warning",LAST); 17 lr_start_transaction("sign_on"); 18 web_submit_data("sign_on", 19 "Action=http://127.0.0.1:1080/WebTours/login.pl", 20 "Method=POST", 21 "TargetFrame=", 22 "RecContentType=text/html", 23 "Referer=http://127.0.0.1:1080/WebTours/login.pl?username=&password=&getInfo=true", 24 "Snapshot=t7.inf", 25 "Mode=HTML", 26 ITEMDATA, 27 "Name=username","Value={username_singon}",ENDITEM, 28 "Name=password","Value={password_signon}",ENDITEM, 29 "Name=passwordConfirm","Value={password_signon}",ENDITEM, 30 "Name=firstName","Value=test",ENDITEM, 31 "Name=lastName","Value=test",ENDITEM, 32 "Name=address1","Value=test",ENDITEM, 33 "Name=address2","Value=test",ENDITEM, 34 "Name=register.x","Value=53",ENDITEM, 35 "Name=register.y","Value=8",ENDITEM, 36 LAST ); 37 38 if(strcmp("Welcome to Web Tours",lr_eval_string("{sign_on}"))==0){ 39 lr_end_transaction("sign_on",LR_PASS); 40 }else{ 41 lr_end_transaction("sign_on",LR_FAIL); 42 lr_error_message("sign_on fail!"); 43 lr_exit(LR_EXIT_ACTION_AND_CONTINUE,LR_AUTO); 44 } 45 46 47 return 0; 48 } 49 /*----------------- login -----------------*/ 50 login() 51 { 52 53 54 lr_start_transaction("webtours_homepage"); 55 web_url("webtours_homepage","url=http://127.0.0.1:1080/WebTours/",LAST); 56 lr_end_transaction("webtours_homepage",LR_AUTO); 57 58 59 web_url("header","url=http://127.0.0.1:1080/WebTours/header.html",LAST); 60 61 web_url("signOff","url=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",LAST); 62 63 web_url("home","url=http://127.0.0.1:1080/WebTours/home.html",LAST); 64 65 66 67 68 69 web_reg_save_param("webtours_login_para","LB=<input type=hidden name=userSession value=","RB=>\n","Search=body",LAST); 70 lr_start_transaction("webtours_loginpage"); 71 web_url("webtours_loginpage","url=http://127.0.0.1:1080/WebTours/nav.pl?in=home",LAST); 72 lr_end_transaction("webtours_loginpage",LR_AUTO); 73 74 75 web_url("nav.pl","url=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",LAST); 76 77 web_url("login.pl","url=http://127.0.0.1:1080/WebTours/login.pl?intro=true",LAST); 78 79 80 web_reg_save_param("login","LB=src=login.pl?intro=","RB= ","Search=body","notfound=warning",LAST); 81 lr_start_transaction("login"); 82 web_submit_data("webtours_login", 83 "Action=http://127.0.0.1:1080/WebTours/login.pl", 84 "Method=POST", 85 "TargetFrame=", 86 "RecContentType=text/html", 87 "Referer=http://127.0.0.1:1080/WebTours", 88 "Snapshot=t7.inf", 89 "Mode=HTML", 90 ITEMDATA, 91 "Name=userSession","Value={webtours_login_para}",ENDITEM, 92 "Name=username","Value={username_singon}",ENDITEM, 93 "Name=password","Value={password_signon}",ENDITEM, 94 "Name=login.x","Value=39",ENDITEM, 95 "Name=login.y","Value=2",ENDITEM, 96 "Name=login","Value=Login",ENDITEM, 97 "Name=JSFormSubmit","Value=off",ENDITEM, 98 LAST ); 99 100 if(strcmp("true",lr_eval_string("{login}"))==0){ 101 lr_end_transaction("login",LR_PASS); 102 }else{ 103 lr_end_transaction("login",LR_FAIL); 104 lr_error_message("webtours login fail!"); 105 lr_exit(LR_EXIT_ACTION_AND_CONTINUE,LR_AUTO); 106 } 107 108 109 110 111 112 113 return 0; 114 } 115 /*----------------- flight -----------------*/ 116 flight() 117 { 118 web_reg_save_param("flight_one","LB=<title>","RB=</title>","Search=body","notfound=warning",LAST); 119 lr_start_transaction("flight_one"); 120 web_submit_data("webtours_login", 121 "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 122 "Method=POST", 123 "TargetFrame=", 124 "RecContentType=text/html", 125 "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", 126 "Snapshot=t7.inf", 127 "Mode=HTML", 128 ITEMDATA, 129 "Name=advanceDiscount","Value=0",ENDITEM, 130 "Name=depart","Value=Denver",ENDITEM, 131 "Name=departDate","Value={departdate}",ENDITEM, 132 "Name=arrive","Value=Denver",ENDITEM, 133 "Name=returnDate","Value={returndate}",ENDITEM, 134 "Name=numPassengers","Value=1",ENDITEM, 135 "Name=seatPref","Value=None",ENDITEM, 136 "Name=seatType","Value=Coach",ENDITEM, 137 "Name=findFlights.x","Value=57",ENDITEM, 138 "Name=findFlights.y","Value=12",ENDITEM, 139 "Name=.cgifields","Value=roundtrip",ENDITEM, 140 "Name=.cgifields","Value=seatType",ENDITEM, 141 "Name=.cgifields","Value=seatPref",ENDITEM, 142 LAST ); 143 144 if(strcmp("Flight Selections",lr_eval_string("{flight_one}"))==0){ 145 lr_end_transaction("flight_one",LR_PASS); 146 }else{ 147 lr_end_transaction("flight_one",LR_FAIL); 148 lr_error_message("reservations fail!"); 149 lr_exit(LR_EXIT_ACTION_AND_CONTINUE,LR_AUTO); 150 } 151 152 153 web_reg_save_param("flight_two","LB=<title>","RB=</title>","Search=body","notfound=warning",LAST); 154 lr_start_transaction("flight_two"); 155 web_submit_data("webtours_login", 156 "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 157 "Method=POST", 158 "TargetFrame=", 159 "RecContentType=text/html", 160 "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 161 "Snapshot=t7.inf", 162 "Mode=HTML", 163 ITEMDATA, 164 "Name=outboundFlight","Value=000;0;{departdate}",ENDITEM, 165 "Name=numPassengers","Value=1",ENDITEM, 166 "Name=advanceDiscount","Value=0",ENDITEM, 167 "Name=seatType","Value=Coach",ENDITEM, 168 "Name=seatPref","Value=None",ENDITEM, 169 "Name=reserveFlights.x","Value=50",ENDITEM, 170 "Name=reserveFlights.y","Value=7",ENDITEM, 171 LAST ); 172 173 if(strcmp("Flight Reservation",lr_eval_string("{flight_two}"))==0){ 174 lr_end_transaction("flight_two",LR_PASS); 175 }else{ 176 lr_end_transaction("flight_two",LR_FAIL); 177 lr_error_message("reservations fail!"); 178 lr_exit(LR_EXIT_ACTION_AND_CONTINUE,LR_AUTO); 179 } 180 181 182 183 web_reg_save_param("flight_three","LB=<title>","RB=</title>","Search=body","notfound=warning",LAST); 184 lr_start_transaction("flight_three"); 185 web_submit_data("webtours_login", 186 "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 187 "Method=POST", 188 "TargetFrame=", 189 "RecContentType=text/html", 190 "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 191 "Snapshot=t7.inf", 192 "Mode=HTML", 193 ITEMDATA, 194 "Name=firstName","Value=Joseph",ENDITEM, 195 "Name=lastName","Value=Marshall",ENDITEM, 196 "Name=address1","Value=234 Willow Drive",ENDITEM, 197 "Name=address2","Value=San Jose/CA/94085",ENDITEM, 198 "Name=pass1","Value=Joseph+Marshall",ENDITEM, 199 "Name=creditCard","Value=123456789",ENDITEM, 200 "Name=expDate","Value=0223",ENDITEM, 201 "Name=oldCCOption","Value=",ENDITEM, 202 "Name=numPassengers","Value=1",ENDITEM, 203 "Name=seatType","Value=Coach",ENDITEM, 204 "Name=seatPref","Value=None",ENDITEM, 205 "Name=outboundFlight","Value=000;0;{departdate}",ENDITEM, 206 "Name=advanceDiscount","Value=0",ENDITEM, 207 "Name=returnFlight","Value=",ENDITEM, 208 "Name=JSFormSubmit","Value=off",ENDITEM, 209 "Name=buyFlights.x","Value=58",ENDITEM, 210 "Name=buyFlights.y","Value=11",ENDITEM, 211 "Name=.cgifields","Value=saveCC",ENDITEM, 212 LAST ); 213 214 if(strcmp("Reservation Made!",lr_eval_string("{flight_three}"))==0){ 215 lr_end_transaction("flight_three",LR_PASS); 216 }else{ 217 lr_end_transaction("flight_three",LR_FAIL); 218 lr_error_message("reservations fail!"); 219 lr_exit(LR_EXIT_ACTION_AND_CONTINUE,LR_AUTO); 220 } 221 return 0; 222 } 223 /*----------------- itinerary -----------------*/ 224 itinerary() 225 { 226 227 int i,length,length2,iTemp; 228 char temp[1024],paras[1024]; 229 lr_start_transaction("welcome"); 230 web_url("welcome.pl","url=http://127.0.0.1:1080/WebTours/welcome.pl?page=itinerary",LAST); 231 lr_end_transaction("welcome",LR_AUTO); 232 233 234 lr_start_transaction("nav"); 235 web_url("nav.pl","url=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=itinerary",LAST); 236 lr_end_transaction("nav",LR_AUTO); 237 238 web_reg_save_param("cgifields","LB=name=\".cgifields\" value=\"","RB=\" />","ord=all","Search=body",LAST); 239 web_reg_save_param("flightID","LB=name=\"flightID\" value=\"","RB=\" />","ord=all","Search=body",LAST); 240 lr_start_transaction("itinerary"); 241 web_url("itinerary.pl","url=http://127.0.0.1:1080/WebTours/itinerary.pl",LAST); 242 lr_end_transaction("itinerary",LR_AUTO); 243 244 length = atoi(lr_eval_string("{flightID_count}")); 245 length2 = atoi(lr_eval_string("{cgifields_count}")); 246 247 strcpy(paras,""); 248 srand(time(NULL)); 249 iTemp=rand()%length+1; 250 251 252 for (i=1;i<=length;i++) { 253 if(i<=iTemp){ 254 sprintf(temp,"{flightID_%d}",i); 255 sprintf(temp,"%d=on&flightID=%s&",i,lr_eval_string(temp)); 256 strcat(paras,temp); 257 }else{ 258 sprintf(temp,"{flightID_%d}",i); 259 sprintf(temp,"flightID=%s&",lr_eval_string(temp)); 260 strcat(paras,temp); 261 } 262 263 } 264 265 266 267 strcat(paras,"removeFlights.x=61&removeFlights.y=12&"); 268 269 270 for(i=1;i<=length2;i++){ 271 272 if(i==length2){ 273 sprintf(temp,"{cgifields_%d}",i); 274 sprintf(temp,".cgifields=%s",lr_eval_string(temp)); 275 strcat(paras,temp); 276 277 }else{ 278 sprintf(temp,"{cgifields_%d}",i); 279 sprintf(temp,".cgifields=%s&",lr_eval_string(temp)); 280 strcat(paras,temp); 281 } 282 283 284 } 285 286 lr_error_message(lr_eval_string(paras)); 287 288 lr_save_string(paras,"paras"); 289 290 lr_start_transaction("cancel_flight"); 291 292 web_custom_request("cancel_flight", 293 "Method=POST", 294 "URL=http://127.0.0.1:1080/WebTours/itinerary.pl", 295 "Body={paras}", 296 "TargetFrame=", 297 LAST ); 298 299 300 lr_end_transaction("cancel_flight",LR_AUTO); 301 302 return 0; 303 } 304 /*----------------- login_out -----------------*/ 305 login_out() 306 { 307 308 lr_start_transaction("login_out"); 309 310 web_url("login_out","url=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",LAST); 311 312 lr_end_transaction("login_out",LR_AUTO); 313 314 return 0; 315 } 316 /*----------------- vuser_end -----------------*/ 317 vuser_end() 318 { 319 return 0; 320 }
以上是关于Loadrunner自带webtours的完整脚本的主要内容,如果未能解决你的问题,请参考以下文章
loadrunner自带订票系统,脚本运行没报错,但是没有成功订票;