qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          LoadRunner登陸功能測試實例

           文中我將介紹LOADRUNNER對事務操作的幾個函數,并通過一個例子,說明LOADRUNNER中事務是否成功是如何判斷的,同時也介紹如何判斷在腳本執行過程中腳本是否真實的執行成功。
            1.先問個問題,我們帶著問題繼續
            錄制一個登陸腳本,對登陸用戶和密碼進行參數化,使前2個用戶名正確,第三個用戶名錯誤,設置腳本迭代3次,分別使用第一個、第二個、第三個用戶登陸,此時在腳本中對登陸的提交操作加一個事務TR_LOGIN,現在提出問題:運行腳本時
            第一個用戶登陸成功,事務TR_LOGIN是否成功?
            第二個用戶登陸成功,事務TR_LOGIN是否成功?
            第三個用戶登陸失敗,事務TR_LOGIN是否成功?
            答案是:TR_LOGIN事務三次執行時均成功
            那有人會問,登陸失敗為什么事務成功?我們一起來看下面的例子,相信在做過例子后就會得到答案!
            我這個例子錄制的是LOADRUNNER自帶的mercuryWebTours
            錄制方法在這里就不介紹了,錄制完成并對用戶名和密碼參數化后的腳本如下:(參數化時其中第三個用戶名是錯誤的)
          Action()
          {
          double trans_time;
          int status;
          web_url("mercuryWebTours",
          "URL=http://127.0.0.1:1080/mercuryWebTours/",
          "Resource=0",
          "RecContentType=text/html",
          "Referer=",
          "Snapshot=t1.inf",
          "Mode=HTML",
          LAST);
          lr_start_transaction("tr_login");
          trans_time=lr_get_transaction_duration( "tr_login" );
          //lr_get_transaction_duration這個函數可以得到事務執行所消耗的時間
          web_reg_find("Text=Error",
          "SaveCount=login_Count", LAST);
          //web_reg_find這個函數可以在相應的范圍內找到要找的內容,和檢查點類似,但這個函數被WEB_FIND多一個參數返回結果,那就是savecount這個值可以記錄在指定范圍內找到指定內容的個數,這個例子中我們就是通過這個值來判斷用戶是否真正的登陸成功
          //說明:在登陸失敗后,登陸頁面會有一個“ERROR”的字符串,所以我們認為如果出現該字符串代表登陸失敗,這個判斷登陸成功或失敗的條件,根據具體的項目不同而不同,根據實際情況而定
          status = web_submit_form("login.pl",
          "Snapshot=t2.inf",
          ITEMDATA,
          "Name=username", "Value={name}", ENDITEM,
          "Name=password", "Value={password}", ENDITEM,
          "Name=login.x", "Value=51", ENDITEM,
          "Name=login.y", "Value=12", ENDITEM,
          LAST);
          //我們把web_submit_form函數執行的結果賦給status這個變量,如果成功返回0,不成功返回大于0的數
          if (status == 0) //如果成功
          lr_end_transaction("tr_login", LR_PASS);//如果提交成功,設置事務狀態為PASS
          else
          lr_end_transaction("tr_login", LR_FAIL);//如果提交失敗,設置事務狀態為FAIL
          if (trans_time) //如果該事務消耗了時間輸出該時間
          lr_output_message("tr_login事務耗時 %f 秒", trans_time);
          else            //如果該事務沒有消耗時間,那么輸出時間不確定
          lr_output_message("The duration cannot be determined.");
          if (atoi(lr_eval_string("{login_Count}")) > 0){
          //如果在登陸后的頁面中找到“ERROR”這個字符串,我們認為登陸失敗
          lr_error_message("Login failed");
          }
          else{
          //否則登陸成功
          lr_output_message("Login successful.");
          return(0);
          }
          return 0;
          }


          好了,執行這個腳本,得到的結果是:
            第一次迭代時:(在這里只粘貼了一部分關鍵的日志)
          Action.c(15): Notify: Transaction "tr_login" started.
          Action.c(17): Registering web_reg_find was successful   [MsgId: MMSG-26390]
          Action.c(20): Notify: Parameter Substitution: parameter "name" = "huruihai"
          Action.c(20): Notify: Parameter Substitution: parameter "password" = "huruihai"
          Action.c(20): Registered web_reg_find successful for "Text=Error"   [MsgId: MMSG-26362]
          Action.c(20): Notify: Saving Parameter "login_Count = 0"
          Action.c(20): web_submit_form("login.pl") was successful, 32673 body bytes, 1652 header bytes   [MsgId: MMSG-26386]
          Action.c(30): Notify: Transaction "tr_login" ended with "Pass" status
          Action.c(35): login事務耗時 0.002523 秒
          Action.c(39): Notify: Parameter Substitution: parameter "login_Count" = "0"
          Action.c(44): Login successful.
            第二次迭代時:
          Action.c(15): Notify: Transaction "tr_login" started.
          Action.c(17): Registering web_reg_find was successful   [MsgId: MMSG-26390]
          Action.c(20): Notify: Parameter Substitution: parameter "name" = "wangjin"
          Action.c(20): Notify: Parameter Substitution: parameter "password" = "wangjin"
          Action.c(20): Registered web_reg_find successful for "Text=Error"   [MsgId: MMSG-26362]
          Action.c(20): Notify: Saving Parameter "login_Count = 0"
          Action.c(20): web_submit_form("login.pl") was successful, 32673 body bytes, 1652 header bytes   [MsgId: MMSG-26386]
          Action.c(30): Notify: Transaction "tr_login" ended with "Pass" status
          Action.c(35): login事務耗時 0.006644 秒
          Action.c(39): Notify: Parameter Substitution: parameter "login_Count" = "0"
          Action.c(44): Login successful.
            第三次迭代時:
          Action.c(15): Notify: Transaction "tr_login" started.
          Action.c(17): Registering web_reg_find was successful   [MsgId: MMSG-26390]
          Action.c(20): Notify: Parameter Substitution: parameter "name" = "errorname"
          Action.c(20): Notify: Parameter Substitution: parameter "password" = "errorpd"
          Action.c(20): Registered web_reg_find successful for "Text=Error" (count=3)   [MsgId: MMSG-26364]
          Action.c(20): Notify: Saving Parameter "login_Count = 3"
          Action.c(20): web_submit_form("login.pl") was successful, 29263 body bytes, 821 header bytes   [MsgId: MMSG-26386]
          Action.c(30): Notify: Transaction "tr_login" ended with "Pass" status (Duration: 0.6840 Wasted Time: 0.0010).
          Action.c(35): login事務耗時 0.005852 秒
          Action.c(39): Notify: Parameter Substitution: parameter "login_Count" = "3"
          Action.c(40): Error: Login failed
          Ending action Action.
            大家可以看到,事務執行結果總是成功的,但最后一次的登陸確是失敗的
            我又把最后一次事務提交的請求地址做了錯誤的參數化,得到的結果是,事務執行失敗

          posted on 2013-11-20 11:18 順其自然EVO 閱讀(617) 評論(0)  編輯  收藏 所屬分類: loadrunner

          <2013年11月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 威宁| 潜江市| 通许县| 屏东县| 准格尔旗| 广宁县| 奉贤区| 洛扎县| 平乐县| 沐川县| 建水县| 平湖市| 平潭县| 大余县| 哈密市| 土默特右旗| 鄂州市| 昭觉县| 高陵县| 舞钢市| 大庆市| 韶山市| 乌兰县| 道真| 西宁市| 阿克陶县| 莎车县| 通道| 乐业县| 且末县| 永和县| 通渭县| 都江堰市| 濉溪县| 商洛市| 敦化市| 尉犁县| 梅河口市| 玉山县| 西青区| 梁山县|