qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          LoadRunner登陸功能測試實例

           文中我將介紹LOADRUNNER對事務(wù)操作的幾個函數(shù),并通過一個例子,說明LOADRUNNER中事務(wù)是否成功是如何判斷的,同時也介紹如何判斷在腳本執(zhí)行過程中腳本是否真實的執(zhí)行成功。
            1.先問個問題,我們帶著問題繼續(xù)
            錄制一個登陸腳本,對登陸用戶和密碼進行參數(shù)化,使前2個用戶名正確,第三個用戶名錯誤,設(shè)置腳本迭代3次,分別使用第一個、第二個、第三個用戶登陸,此時在腳本中對登陸的提交操作加一個事務(wù)TR_LOGIN,現(xiàn)在提出問題:運行腳本時
            第一個用戶登陸成功,事務(wù)TR_LOGIN是否成功?
            第二個用戶登陸成功,事務(wù)TR_LOGIN是否成功?
            第三個用戶登陸失敗,事務(wù)TR_LOGIN是否成功?
            答案是:TR_LOGIN事務(wù)三次執(zhí)行時均成功
            那有人會問,登陸失敗為什么事務(wù)成功?我們一起來看下面的例子,相信在做過例子后就會得到答案!
            我這個例子錄制的是LOADRUNNER自帶的mercuryWebTours
            錄制方法在這里就不介紹了,錄制完成并對用戶名和密碼參數(shù)化后的腳本如下:(參數(shù)化時其中第三個用戶名是錯誤的)
          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這個函數(shù)可以得到事務(wù)執(zhí)行所消耗的時間
          web_reg_find("Text=Error",
          "SaveCount=login_Count", LAST);
          //web_reg_find這個函數(shù)可以在相應(yīng)的范圍內(nèi)找到要找的內(nèi)容,和檢查點類似,但這個函數(shù)被WEB_FIND多一個參數(shù)返回結(jié)果,那就是savecount這個值可以記錄在指定范圍內(nèi)找到指定內(nèi)容的個數(shù),這個例子中我們就是通過這個值來判斷用戶是否真正的登陸成功
          //說明:在登陸失敗后,登陸頁面會有一個“ERROR”的字符串,所以我們認為如果出現(xiàn)該字符串代表登陸失敗,這個判斷登陸成功或失敗的條件,根據(jù)具體的項目不同而不同,根據(jù)實際情況而定
          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函數(shù)執(zhí)行的結(jié)果賦給status這個變量,如果成功返回0,不成功返回大于0的數(shù)
          if (status == 0) //如果成功
          lr_end_transaction("tr_login", LR_PASS);//如果提交成功,設(shè)置事務(wù)狀態(tài)為PASS
          else
          lr_end_transaction("tr_login", LR_FAIL);//如果提交失敗,設(shè)置事務(wù)狀態(tài)為FAIL
          if (trans_time) //如果該事務(wù)消耗了時間輸出該時間
          lr_output_message("tr_login事務(wù)耗時 %f 秒", trans_time);
          else            //如果該事務(wù)沒有消耗時間,那么輸出時間不確定
          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;
          }


          好了,執(zhí)行這個腳本,得到的結(jié)果是:
            第一次迭代時:(在這里只粘貼了一部分關(guān)鍵的日志)
          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事務(wù)耗時 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事務(wù)耗時 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事務(wù)耗時 0.005852 秒
          Action.c(39): Notify: Parameter Substitution: parameter "login_Count" = "3"
          Action.c(40): Error: Login failed
          Ending action Action.
            大家可以看到,事務(wù)執(zhí)行結(jié)果總是成功的,但最后一次的登陸確是失敗的
            我又把最后一次事務(wù)提交的請求地址做了錯誤的參數(shù)化,得到的結(jié)果是,事務(wù)執(zhí)行失敗

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

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

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 巨野县| 孟连| 天台县| 鱼台县| 东阳市| 泾川县| 阿鲁科尔沁旗| 泰宁县| 那曲县| 石首市| 丹棱县| 林周县| 贵南县| 西充县| 夏邑县| 浠水县| 东兰县| 荆门市| 常山县| 福建省| 行唐县| 陕西省| 垦利县| 调兵山市| 屏边| 资源县| 宜春市| 安西县| 永吉县| 新兴县| 民和| 十堰市| 申扎县| 和田县| 耒阳市| 许昌县| 雷山县| 澄城县| 高雄市| 交口县| 永年县|