用LoadRunner開發開心網外掛

TIB發表於2010-02-24

現在基於WEB頁面的網路遊戲越來越流行,由於是基於HTTP的,因此應該可以用LoadRunner來開發外掛。今天略為試了一下,證實是可行的。

 

以開心網的爭車位遊戲為例,用LoadRunner錄製WebHTTP/HTML)指令碼,並進行適當的修改,主要是做一些關聯和引數化。為速度起見,刪掉一些資源請求的指令碼。

 

指令碼摘錄如下:

 

Action()

{

 

       char *parkID;

      

       web_add_cookie("_uid=72750415; DOMAIN=www.kaixin001.com");

 

       /* 訪問開心網主頁*/

       web_url("www.kaixin001.com",

              "URL=http://www.kaixin001.com/",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=",

              "Snapshot=t1.inf",

              "Mode=HTML",

              EXTRARES,

              //"Url=http://img1.kaixin001.com.cn/i/n_bg_r.gif", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i/index_app.gif", ENDITEM,

              LAST);

 

       /*登入*/

       web_submit_form("login.php",

              "Snapshot=t2.inf",

              ITEMDATA,

              "Name=email", "Value=XXXX @126.com", ENDITEM,

              "Name=password", "Value=XXXX", ENDITEM,

              "Name=remember", "Value=<OFF>", ENDITEM,

              EXTRARES,

//           "Url=http://img1.kaixin001.com.cn/i/small-tri.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/r_sj.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/r_xx13.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/ddtx.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/account_set.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/pri_set.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/app_set.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/home/pay.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/ns_bg.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i2/xiasanjiao.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/index_app_add1.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/index_app_set1.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/dl_tsk.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/app_sprite_03.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/l120_s.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/home/hide_tips.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://s.kaixin001.com.cn/css/reg2.css", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

//           "Url=http://img1.kaixin001.com.cn/i/inv/iv_nofbg.gif", "Referer=http://www.kaixin001.com/home/?uid=72750415", ENDITEM,

              LAST);

 

 

 

/*此處,刪掉一些指令碼(為速度起見),如果是為了做壓力測試則不要刪除!*/

// ……

 

 

 

       /*進入爭車位遊戲*/

       // 這裡要做一下關聯,因為後面很多URL要使用“verify=”,相當於session id的作用

web_reg_save_param("verify_id",

                                      "LB=var g_verify = /"",

                                      "RB=/";",

                                      LAST);

 

       web_url("index.php",

              "URL=http://www.kaixin001.com/!parking/index.php?t=43",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=http://www.kaixin001.com/home/?uid=72750415",

              "Snapshot=t12.inf",

              "Mode=HTML",

              EXTRARES,

              //"Url=http://img1.kaixin001.com.cn/i2/park/daoju.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/sy.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/cs.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/ph.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=../swf/parking/parking-3.swf", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img.kaixin001.com.cn/i/50_0_0.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/ll.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/help.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i/l50_bg_s.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/logo_alto.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://pic.kaixin001.com.cn/pic/car/0/0/2_1_7-16776960.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/wdqc.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/bar_off.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/park/p2.gif", "Referer=http://www.kaixin001.com/!parking/index.php?t=43", ENDITEM,

              //"Url=http://img.kaixin001.com.cn/i/20_0_0.gif", "Referer=http://www.kaixin001.com/swf/parking/parking-3.swf", ENDITEM,

              //"Url=http://img1.kaixin001.com.cn/i2/scenes/bb2_1.jpg", "Referer=http://www.kaixin001.com/swf/parking/parking-3.swf", ENDITEM,

              LAST);

 

       lr_output_message(lr_eval_string("{verify_id}"));

 

 

      web_submit_data("i.php",

             "Action=http://www.kaixin001.com/interface/i.php",

             "Method=POST",

             "RecContentType=text/html",

             "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

             "Snapshot=t13.inf",

             "Mode=HTML",

             ITEMDATA,

             "Name=id", "Value=0", ENDITEM,

             "Name=class", "Value=parking", ENDITEM,

             EXTRARES,

            "Url=http://img1.kaixin001.com.cn/i2/scenes/bb2_1.jpg", "Referer=http://www.kaixin001.com/swf/parking/parking-3.swf", ENDITEM,

             LAST);

 

      web_url("js_2",

             "URL=http://m061156.kaixin001.com/ifr/js?r=http://s.kaixin001.com.cn/js/kxbase-1.js&r=http://s.kaixin001.com.cn/js/presence-12.js&rnd=0.2048821490060942",

             "Resource=0",

             "RecContentType=text/html",

             "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

             "Snapshot=t14.inf",

             "Mode=HTML",

             EXTRARES,

             "Url=../g/0.8747909947221656/72750415/ctx?_=1267005255776", "Referer=http://m061156.kaixin001.com/ifr/js?r=http://s.kaixin001.com.cn/js/kxbase-1.js&r=http://s.kaixin001.com.cn/js/presence-12.js&rnd=0.2048821490060942", ENDITEM,

             "Url=../k/0.44502850747019995/72750415/2?_=1267005226418", "Referer=http://m061156.kaixin001.com/ifr/js?r=http://s.kaixin001.com.cn/js/kxbase-1.js&r=http://s.kaixin001.com.cn/js/presence-12.js&rnd=0.8299689421343095", ENDITEM,

             LAST);

 

       /*選擇爭車位物件*/

       lr_save_string("1","Friend_ID");// 第幾位

 

       // 取到伺服器返回的所有車位ID

       web_reg_save_param("parkid",

                       "LB=parkid/":/"",

                                      "RB=/",/"car_uid/":0,/"carid/":0,/"",

                                      "ORD=All",

                                      LAST);

 

       web_submit_data("!neighbor.php",

              "Action=http://www.kaixin001.com/!parking/!neighbor.php",

              "Method=POST",

              "RecContentType=text/html",

              "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

              "Snapshot=t15.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=verify", "Value={verify_id}", ENDITEM,

              "Name=puid", "Value={Friend_ID}", ENDITEM,

              EXTRARES,

              "Url=http://img.kaixin001.com.cn/i2/park/f9.jpg", "Referer=http://www.kaixin001.com/swf/parking/parking-3.swf", ENDITEM,

              "Url=http://pic.kaixin001.com.cn/pic/car/0/0/1_1_7-16776960.swf", "Referer=http://www.kaixin001.com/swf/parking/parking-3.swf", ENDITEM,

              "Url=http://m061156.kaixin001.com/k/0.5935958843488411/72750415/2?_=1267005256713", "Referer=http://m061156.kaixin001.com/ifr/js?r=http://s.kaixin001.com.cn/js/kxbase-1.js&r=http://s.kaixin001.com.cn/js/presence-12.js&rnd=0.2048821490060942", ENDITEM,

              LAST);

 

       // 選擇車

       web_url("!selcar.php",

              "URL=http://www.kaixin001.com/!parking/!selcar.php?verify={verify_id}",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

              "Snapshot=t31.inf",

              "Mode=HTML",

              LAST);

 

       lr_output_message("選擇第一個停車位:");

       parkID = lr_paramarr_idx("parkid",1);

       lr_output_message(parkID);

       lr_save_string(parkID,"SelectedParkID");

 

       /*確定提交*/

       web_submit_data("!park.php",

              "Action=http://www.kaixin001.com/!parking/!park.php",

              "Method=POST",

              "RecContentType=text/html",

              "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

              "Snapshot=t32.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=verify", "Value={verify_id}", ENDITEM,

              "Name=park_uid", "Value={Friend_ID}", ENDITEM, /

              "Name=parkid", "Value={SelectedParkID}", ENDITEM, // 選擇停車位的ID

              "Name=carid", "Value=65541", ENDITEM, // 自己車的ID

              "Name=neighbor", "Value={Friend_ID}", ENDITEM,

              "Name=acc", "Value=-goodness-a550", ENDITEM,

              "Name=first_fee_parking", "Value=0", ENDITEM,

              LAST);

 

       web_submit_data("!neighbor.php_2",

              "Action=http://www.kaixin001.com/!parking/!neighbor.php",

              "Method=POST",

              "RecContentType=text/html",

              "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

              "Snapshot=t33.inf",

              "Mode=HTML",

              ITEMDATA,

              "Name=verify", "Value={verify_id}", ENDITEM,

              "Name=puid", "Value={Friend_ID}", ENDITEM,

              EXTRARES,

              "Url=http://pic.kaixin001.com.cn/pic/car/0/0/1_1_7-16776960.swf", "Referer=http://www.kaixin001.com/swf/parking/parking-3.swf", ENDITEM,

              "Url=http://m061156.kaixin001.com/k/0.4103570536393127/72750415/2?_=1267009448290", "Referer=http://m061156.kaixin001.com/ifr/js?r=http://s.kaixin001.com.cn/js/kxbase-1.js&r=http://s.kaixin001.com.cn/js/presence-12.js&rnd=0.2276323110065261", ENDITEM,

              LAST);

 

 

       /*退出*/

       web_url("logout.php",

              "URL=http://www.kaixin001.com/login/logout.php",

              "Resource=0",

              "RecContentType=text/html",

              "Referer=http://www.kaixin001.com/!parking/index.php?t=43",

              "Snapshot=t16.inf",

              "Mode=HTML",

              LAST);

 

       return 0;

}

相關文章