Loadrunner 关联 web_custom_request,针对自带的订票系统的一个综合实例,相信看了本文大家对学习loadrunner脚本会有很大的帮助.
本实例要解决的问题:(1)动态删除Loadrunner订票系统的一条订单;(2)动态判断表单订单条目,执行取消第一条订单;(3)Loadrunner 关联 web_custom_request以及循环语句的应用。
代码不足之处:变量定义太多,希望和大家共同交流。
以下为我的脚本的源码:
------------------------------------------------------
#include "web_api.h"
Action()
{
int i,k;
char form[1024];
char temp[1024];
char tmp[1024];
char tp[1024];
char tp1[1024];
char tp2[1024];
web_url("MercuryWebTours",
"URL=http://192.168.8.9/MercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(10);
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=zhangming", ENDITEM,
"Name=password", "Value=666666", ENDITEM,
"Name=login.x", "Value=50", ENDITEM,
"Name=login.y", "Value=11", ENDITEM,
LAST);
lr_think_time(4);
web_reg_save_param("flightID",
"LB=INPUT TYPE=\"hidden\" NAME=\"flightID\" VALUE=\"",
"RB=\"",
"ORD=ALL",
"search=body",
LAST);
web_image("Itinerary Button",
"Alt=Itinerary Button",
"Snapshot=t3.inf",
LAST);
strcpy(form,"Body=1=on");
i=atoi(lr_eval_string("{flightID_count}"));
for(k=1;k<=i;k++)
{
sprintf(temp,"{flightID_%d}",k);
strcpy(tmp,lr_eval_string(temp));// 取出flightID的值,并把值传给tmp
sprintf(tp,"&flightID=%s",tmp);
strcat(form,tp);
}
for(k=1;k<=i;k++)
{
sprintf(tp2,"&.cgifields=%d",k);
strcat(tp1,tp2);
}
strcat(form,tp1);
strcat(form,"&removeFlights.x=137&removeFlights.y=13");
lr_output_message("form 的值为=%s",form);
web_custom_request("itinerary.pl",
"url=http://192.168.8.9/MercuryWebTours/itinerary.pl",
"Method=POST",
"RecContentType=text/xml",
form,
"Snapshot=t7.inf",
LAST);
return 0;
}
文章来源于领测软件测试网 https://www.ltesting.net/