LoadRunner的脚本优化

Replay log的报错信息:

Action.c(30): Error: C interpreter run time error: Action.c (30):  Error -- memory violation : Exception ACCESS_VIOLATION received.

  

  compile通过,可是运行的时候就报错误信息.到第30行看:

if(strcmp(lr__string("{num}"),0)==0)

  反复和资料上的对比,一模一样.为什么人家可以运行,猫猫却不可以.于是跑去CDSN下了一个函数大全来看:

// strcmp 比较 string1 和 string2 以确定字母排序的次序。
int strcmp ( const char *string1, const char *string2 );

  于是猫猫试着将其改成:

if(strcmp(lr__string("{num}"),"0")==0)

  Run succeed!

  

Virtual User Script started
Starting action vuser_init.
Web Turbo Replay of LoadRunner 9.0.0 for WINXP; WebReplay82 build 5727   [MsgId: MMSG-27143]
Run-Time Settings file: "E:\Program Files\Mercury\LoadRunner\scripts\Shopping\\default.cfg"   [MsgId: MMSG-27141]
vuser_init.c(12): web_url("index.jsp") was successful, 451 body bytes, 214 header bytes   [MsgId: MMSG-26386]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Warning -27077: The "vuser_init" section contains web function(s) when the "Simulate a new user on each iteration" Run-Time Setting is ON.  This may produce unpredictable results with multiple iterations   [MsgId: MWAR-27077]
Starting action Action.
Action.c(7): Rendezvous LoginPoint
Action.c(10): Registering web_reg_find was successful   [MsgId: MMSG-26390]
Action.c(15): Registered web_reg_find successful for "Text=购买" (count=5)   [MsgId: MMSG-26364]
Action.c(15): web_submit_data("user.do") was successful, 1164 body bytes, 142 header bytes   [MsgId: MMSG-26386]
用户名: admin
5
登陆成功
Ending action Action.
Starting action Shopping_Action.
Shopping_Action.c(7): Notify: Transaction "Shopping_Transaction" started.
Shopping_Action.c(9): web_url("merchandise.do") was successful, 1189 body bytes, 142 header bytes  [MsgId: MMSG-26386]
Shopping_Action.c(18): Linking to "http://localhost:8080/shopping/merchandise.do?operate=toBag&id=2", Target Frame=""   [MsgId: MMSG-27994]
Shopping_Action.c(18): web_link("购买") was successful, 1191 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Shopping_Action.c(25): Notify: Transaction "Shopping_Transaction" ended with "Pass" status (Duration: 0.3382).
Ending action Shopping_Action.
Starting action bag_Action.
bag_Action.c(6): web_url("bag.jsp") was successful, 1527 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Ending action bag_Action.
Starting action updateBag_Action.
updateBag_Action.c(6): web_submit_data("merchandise.do_2") was successful, 1544 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Ending action updateBag_Action.
Starting action clearBag_Action.
clearBag_Action.c(6): web_url("merchandise.do_3") was successful, 977 body bytes, 141 header bytes   [MsgId: MMSG-26386]
Ending action clearBag_Action.
Ending iteration 1.
Starting iteration 2.
Starting action Action.
Action.c(7): Rendezvous LoginPoint
Action.c(10): Registering web_reg_find was successful   [MsgId: MMSG-26390]
Action.c(15): Continuing after Error -26366: "Text=购买" not found for web_reg_find   [MsgId: MERR-26366]
Action.c(15): web_submit_data("user.do") highest severity level was "continue on error", 467 body bytes, 141 header bytes   [MsgId: MMSG-26388]
Action.c(15): Continuing after error in Vuser script.
用户名: 123
0
登录失败

Ending action Action.
Starting action Shopping_Action.
Shopping_Action.c(7): Notify: Transaction "Shopping_Transaction" started.
Shopping_Action.c(9): web_url("merchandise.do") was successful, 1189 body bytes, 142 header bytes  [MsgId: MMSG-26386]
Shopping_Action.c(18): Linking to "http://localhost:8080/shopping/merchandise.do?operate=toBag&id=2", Target Frame=""   [MsgId: MMSG-27994]
Shopping_Action.c(18): web_link("购买") was successful, 1191 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Shopping_Action.c(25): Notify: Transaction "Shopping_Transaction" ended with "Pass" status (Duration: 0.1736).
Ending action Shopping_Action.
Starting action bag_Action.
bag_Action.c(6): web_url("bag.jsp") was successful, 1527 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Ending action bag_Action.
Starting action updateBag_Action.
updateBag_Action.c(6): web_submit_data("merchandise.do_2") was successful, 1544 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Ending action updateBag_Action.
Starting action clearBag_Action.
clearBag_Action.c(6): web_url("merchandise.do_3") was successful, 977 body bytes, 141 header bytes   [MsgId: MMSG-26386]
Ending action clearBag_Action.
Ending iteration 2.
Ending Vuser...
Starting action vuser_end.
vuser_end.c(6): web_url("merchandise.do_4") was successful, 1164 body bytes, 142 header bytes   [MsgId: MMSG-26386]
Ending action vuser_end.
Vuser Terminated.
----

脚本优化练习代码如下:

Action:

 lr_rendezvous("LoginPoint");//登录的集合点

 web_reg_find("Fail=NotFound",
  "Search=Body",
  "SaveCount=num",
  "Text=购买",
  LAST);
 web_submit_data("user.do",
  "Action=http://localhost:8080/shopping/user.do?operate=login",
  "Method=POST",
  "RecContentType=text/html",
  "Referer=http://localhost:8080/shopping/index.jsp",
  "Snapshot=t2.inf",
  "Mode=HTML",
  ITEMDATA,
  "Name=user.name", "Value={Name}", ENDITEM,
  "Name=user.pass", "Value=admin", ENDITEM,
  LAST);

 lr_log_message("用户名: %s", lr__string("{Name}"));
 lr_log_message("%s",lr__string("{num}"));

 if(strcmp(lr__string("{num}"),"0")==0)
  lr_log_message("登录失败");
 else
  lr_log_message("登陆成功");

 

Shopping_Action:

 lr_start_transaction("Shopping_Transaction");

 web_url("merchandise.do",
  "URL=http://localhost:8080/shopping/merchandise.do?operate=toBag&id=1",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=http://localhost:8080/shopping/user.do?operate=login",
  "Snapshot=t3.inf",
  "Mode=HTML",
  LAST);

 web_link("购买",
  "Text=购买",
  "Ordinal=2",
  "Snapshot=t4.inf",
  LAST);


 lr_end_transaction("Shopping_Transaction", LR_AUTO);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值