业务流程:用户登录-搜索书籍-预订书籍
其中登录输入用户名和密码;搜索输入书籍名称点击button搜索;预订需要在书籍搜索结果点击书籍后面的request按钮,进入request页面,填写日期相关信息点击提交。
开始计划时,感觉这个脚本是最好录制的,于是把计划排在后面,但是在实际操作中遇到难题。
1.在预订书籍这个事务中,有二次提交数据,第一次是把书籍内容提交到表单,第二次是提交预订日期等信息。但是在这两次提交的数据中,找不到跟书籍有关的任何信息,无法对预订书籍事务进行参数化。
解决方法:
尝试1:对脚本中所有出现书籍名称的字段进行参数化,二个参数运行二次,第一次成功,第二次失败
尝试2:搜索的时候仅搜索出唯一一本书籍,只参数化搜索事务,二个参数运行二次,第一次成功,第二次失败
尝试3:设置loadrunner-record option-HTTP Property-Advanced-Header-Record header not in list. 重新录制,发现脚本多了许多web_add_auto_header,web_revert_auto_header函数,搜索的时候仅搜索出唯一一本书籍,只参数化搜索事务,二个参数运行二次,第一次成功,第二次失败
尝试4:协议选择AJAX,设置loadrunner-record option-HTTP Property-Advanced-Header-Record header not in list。设置参数二次运行二次,均成功。
AJAX预订脚本如下:
//search one book and request this book
lr_start_transaction("search");
lr_think_time(24);
//input book name
web_edit_field("query",
"Snapshot=t4.inf",
DESCRIPTION,
"Type=text",
"Name=query",
ACTION,
"SetValue={title}",
LAST);
//if on search result,this text will display
web_reg_find("Text=No results were found for your search request",
"SaveCount=count2",
LAST);
//click search button
web_button("INPUT_2",
"Snapshot=t5.inf",
DESCRIPTION,
"Type=submit",
"Tag=INPUT",
"ID=search_submit",
ACTION,
"UserAction=Click",
LAST);
if (atoi(lr_eval_string("{count2}"))==0)
{
lr_end_transaction("search", LR_PASS);
lr_output_message("search suss,because %d", atoi(lr_eval_string("{count2}")));
lr_output_message("search title is %s",lr_eval_string("{title}"));
}
else
{
lr_end_transaction("search", LR_FAIL);
lr_error_message("search fail,because %d", atoi(lr_eval_string("{count2}")));
}
//starting request transaction
lr_start_transaction("request");
lr_think_time(10);
web_check_box("listItems",
"Snapshot=t6.inf",
DESCRIPTION,
"Name=listItems",
ACTION,
"Set=ON",
LAST);
//click the request button
web_text_link("Request",
"Snapshot=t7.inf",
DESCRIPTION,
"Text=Request",
ACTION,
"UserAction=Click",
LAST);
lr_think_time(13);
web_list("mainLocationFilter",
"Snapshot=t8.inf",
DESCRIPTION,
"Name=mainLocationFilter",
ACTION,
"Select=Hong Kong Central (*1000000)",
LAST);
lr_think_time(5);
web_edit_field("expirationDate",
"Snapshot=t9.inf",
DESCRIPTION,
"Type=text",
"Name=expirationDate",
ACTION,
"SetValue=2011/08/08",
LAST);
web_reg_find("Text=Transaction Reference Number",
"SaveCount=count3",
LAST);
web_reg_find("Text=Your request has been submitted",
"SaveCount=count4",
LAST);
web_button("INPUT_3",
"Snapshot=t10.inf",
DESCRIPTION,
"Type=submit",
"Tag=INPUT",
"ID=id52",
ACTION,
"UserAction=Click",
LAST);
if (atoi(lr_eval_string("{count3}"))==1&&atoi(lr_eval_string("{count4}"))==1)
{
lr_end_transaction("request", LR_PASS);
lr_output_message("request suss,because %d", atoi(lr_eval_string("{count3}")));
}
else
{
lr_end_transaction("request", LR_FAIL);
lr_error_message("request fail,because %d", atoi(lr_eval_string("{count4}")));
}
张洪杰 2011-07-04
焦爱玲: 学习下
只是皮毛,共同学习
张洪杰 2011-07-05
小窝: 同步至官方微博
继续学习
焦爱玲 2011-07-14
张洪杰: 只是皮毛,共同学习