|
用的是LR自带的网站编写的脚本,事务有登录,查看航班,订机票三个事务。在登录设置了检查,在查看航班进行了地点的参数化,其中在订票由于地点的变化需要进行关联,在显示信息由于时间的变化需要关联。
脚本
#include "web_api.h"
Action()
{
double time;
web_url("mercuryWebTours",
"URL=http://localhost:1080/mercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time( 7 );
lr_start_transaction("登录");
time=lr_get_transaction_duration( "登录" ); //事务执行所消耗的时间
web_reg_find("Text=222",
"SaveCount=login_Count",
LAST); //检查是否成功登录
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=222", ENDITEM,
"Name=password", "Value=222", ENDITEM,
"Name=login.x", "Value=56", ENDITEM,
"Name=login.y", "Value=18", ENDITEM,
LAST);
lr_end_transaction("登录", LR_AUTO);
if (time)
lr_output_message("登录事务耗时 %f 秒", time); //如果该事务消耗了时间输出该时间
else
lr_output_message("如果该事务没有消耗时间,那么输出时间不确定.");
if (atoi(lr_eval_string("{login_Count}")) > 0)
{
lr_output_message("登录成功."); //如果在登陆后的页面中找到"111"这个字符串,我们认为登陆成功
}
else{
lr_error_message("登录失败"); //否则登陆失败
}
lr_start_transaction("查看航班");
web_reg_save_param( "WCSParam_Diff2",
"LB= NAME=\"",
"RB=\"",
"Ord=6",
"Search=Body",
"RelFrameId=1.2",
LAST );
web_reg_save_param( "WCSParam_Diff3",
"LB= VALUE=\"",
"RB=\"",
"Ord=12",
"Search=Body",
"RelFrameId=1.2", //对日期进行关联
LAST );
web_reg_save_param( "WCSParam_Diff4",
"LB= VALUE=\"",
"RB=\"",
"Ord=25",
"Search=Body",
"RelFrameId=1.2",
LAST );
web_image("Search Flights Button",
"Alt=Search Flights Button",
"Snapshot=t3.inf",
LAST);
lr_end_transaction("查看航班", LR_AUTO);
lr_think_time( 1 );
web_reg_save_param( "WCSParam_Diff1",
"LB=outboundFlight value=", //对订票进行关联
"RB= ",
"Ord=1",
"Search=Body",
"RelFrameId=1",
LAST );
web_submit_form("reservations.pl",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart", "Value={qidian}", ENDITEM, //对出发点进行参数化
"Name=departDate", "Value={WCSParam_Diff3}", ENDITEM,
"Name=arrive", "Value={zhongdian}", ENDITEM, //对到达点进行参数化
"Name={WCSParam_Diff2}", "Value={WCSParam_Diff4}", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=roundtrip", "Value=<OFF>", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=findFlights.x", "Value=53", ENDITEM,
"Name=findFlights.y", "Value=17", ENDITEM,
LAST);
lr_output_message("出发地点------%s",lr_eval_string("{qidian}"));
lr_output_message("到达地点------%s",lr_eval_string("{zhongdian}")); //输出出发点和到达点
lr_start_transaction("订机票");
time=lr_get_transaction_duration( "订机票" ); //事务执行所消耗的时间
web_submit_form("reservations.pl_2",
"Snapshot=t5.inf",
ITEMDATA,
"Name=outboundFlight", "Value={WCSParam_Diff1}", ENDITEM,
"Name=reserveFlights.x", "Value=71", ENDITEM,
"Name=reserveFlights.y", "Value=16", ENDITEM,
LAST);
lr_end_transaction("订机票", LR_AUTO);
if (time)
lr_output_message("订机票事务耗时 %f 秒", time); //如果该事务消耗了时间输出该时间
else
lr_output_message("如果该事务没有消耗时间,那么输出时间不确定.");
lr_think_time( 13 );
web_submit_form("reservations.pl_3",
"Snapshot=t6.inf",
ITEMDATA,
"Name=firstName", "Value=222", ENDITEM,
"Name=lastName", "Value=222", ENDITEM,
"Name=address1", "Value=222", ENDITEM,
"Name=address2", "Value=222", ENDITEM,
"Name=pass1", "Value= 222222", ENDITEM,
"Name=creditCard", "Value=22222222", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=saveCC", "Value=<OFF>", ENDITEM,
"Name=buyFlights.x", "Value=52", ENDITEM,
"Name=buyFlights.y", "Value=18", ENDITEM,
LAST);
lr_think_time( 5 );
web_image("SignOff Button",
"Alt=SignOff Button",
"Snapshot=t7.inf",
LAST);
return 0;} |
|