虚幻的世界,真实的人,一起测试吧!欢迎各位的加入!新空间地址:http://blog.chinaunix.net/blog/index.html

loadrunner对事务状态的跟踪 (转)

上一篇 / 下一篇  2009-02-13 17:16:37 / 个人分类:学习

本篇日志中我将介绍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.


        大家可以看到,事务执行结果总是成功的,但最后一次的登陆确是失败的

        我又把最后一次事务提交的请求地址做了错误的参数化,得到的结果是,事务执行失败

        好了得出结论:

        事务是否执行成功,是根据服务器是否有正确的回应,而与业务逻辑本身没有关系

        本人对LOADRUNNER也是在摸索中,如果文章有写的不对,或理解错误的地方请指出,不甚感激


TAG: 学习

 

评分:0

我来说两句

dsy851009

dsy851009

王者风范,大家闺秀!

日历

« 2024-04-19  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 19058
  • 日志数: 21
  • 建立时间: 2008-11-03
  • 更新时间: 2012-06-11

RSS订阅

Open Toolbar