loadrunner提高篇 - 关联技术的经典使用
关联函数是一个查找函数,即是从HTML文件内容中查找需要的值,并将其保存在一个变量或数组中。换一个角度看,关联函数不单单可以匹配一些变化的值,同样可以匹配一些固定的内容,并将其保存到一个数据组,供后续业务使用,也即对关联函数进行扩展使用,在处理事务中这种方式经常用到。
实例:以订票为例,假设要实现这样的事务,选择好出发城市和到达城市后,在选择航班时,需要选择票价最便宜的航班
实现思路:首先使用关联函数读取HTML代码中票价和航班号,分别将两部分的数据保存在不同的数组中;接着比较票价,选择找到票价最低的是数组中的第几个元素,即最便宜机票所在数据的下标;最后将该下标的值对应地读出航班号,就是最便宜的航班。
完整代码如下:
【注:还没运行成功,主要是不懂代码函数的运用】
Action()
{
//录制订票脚本,为了练习关联技术的经典使用
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTTP",
LAST); web_url("header.html",
"URL=http://127.0.0.1:1080/WebTours/header.html",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/",
"Snapshot=t4.inf",
"Mode=HTTP",
LAST); web_concurrent_start(NULL); web_url("hp_logo.png",
"URL=http://127.0.0.1:1080/WebTours/images/hp_logo.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://127.0.0.1:1080/WebTours/header.html",
"Snapshot=t5.inf",
LAST); web_url("webtours.png",
"URL=http://127.0.0.1:1080/WebTours/images/webtours.png",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/header.html",
"Mode=HTTP",
LAST); web_concurrent_end(NULL); web_url("welcome.pl",
"URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/",
"Snapshot=t6.inf",
"Mode=HTTP",
LAST); web_concurrent_start(NULL); web_url("nav.pl",
"URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",
"Snapshot=t7.inf",
"Mode=HTTP",
LAST); web_url("home.html",
"URL=http://127.0.0.1:1080/WebTours/home.html",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",
"Snapshot=t8.inf",
"Mode=HTTP",
LAST); web_concurrent_end(NULL); web_url("mer_login.gif",
"URL=http://127.0.0.1:1080/WebTours/images/mer_login.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t9.inf",
LAST); web_concurrent_start(NULL); web_url("8afc2fe48db9060fe1bdda2089e1d950.png",
"URL=http://act.cmcmcdn.com/upload/201507/8afc2fe48db9060fe1bdda2089e1d950.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://127.0.0.1:1080/WebTours/",
"Snapshot=t10.inf",
LAST); web_url("3b491068507d8f85ea7b35d756da7215.png",
"URL=http://act.cmcmcdn.com/upload/201507/3b491068507d8f85ea7b35d756da7215.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://127.0.0.1:1080/WebTours/",
"Snapshot=t11.inf",
LAST); web_concurrent_end(NULL); lr_start_transaction("登录"); lr_think_time(); web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t12.inf",
"Mode=HTTP",
ITEMDATA,
"Name=userSession", "Value=120844.899311462zcVfQfQpfAiDDDDDDHcQfpHfHAf", ENDITEM,
"Name=username", "Value=test1", ENDITEM,
"Name=password", "Value=test1", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=36", ENDITEM,
"Name=login.y", "Value=15", ENDITEM,
LAST); web_concurrent_start(NULL); web_url("nav.pl_2",
"URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/login.pl",
"Snapshot=t13.inf",
"Mode=HTTP",
LAST); web_url("login.pl_2",
"URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/login.pl",
"Snapshot=t18.inf",
"Mode=HTTP",
LAST); web_concurrent_end(NULL); web_concurrent_start(NULL); web_url("flights.gif",
"URL=http://127.0.0.1:1080/WebTours/images/flights.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t14.inf",
LAST); web_url("in_home.gif",
"URL=http://127.0.0.1:1080/WebTours/images/in_home.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t15.inf",
LAST); web_url("signoff.gif",
"URL=http://127.0.0.1:1080/WebTours/images/signoff.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t16.inf",
LAST); web_url("itinerary.gif",
"URL=http://127.0.0.1:1080/WebTours/images/itinerary.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t17.inf",
LAST); web_concurrent_end(NULL); lr_end_transaction("登录", LR_AUTO); lr_start_transaction("订票"); lr_think_time(); web_url("Search Flights Button",
"URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",
"Snapshot=t19.inf",
"Mode=HTTP",
LAST); web_concurrent_start(NULL); web_url("reservations.pl",
"URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",
"Snapshot=t20.inf",
"Mode=HTTP",
LAST); web_url("nav.pl_3",
"URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",
"Snapshot=t21.inf",
"Mode=HTTP",
LAST); web_concurrent_end(NULL); web_url("button_next.gif",
"URL=http://127.0.0.1:1080/WebTours/images/button_next.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",
"Snapshot=t22.inf",
LAST); web_concurrent_start(NULL); web_url("in_flights.gif",
"URL=http://127.0.0.1:1080/WebTours/images/in_flights.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",
"Snapshot=t23.inf",
LAST); web_url("home.gif",
"URL=http://127.0.0.1:1080/WebTours/images/home.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",
"Snapshot=t24.inf",
LAST); web_concurrent_end(NULL); lr_think_time();
/*分析票价和航班号的左右边界值后(可通过航班信息的HTML源代码分析),在这里插入关联函数,进行关联时Ordinal的属性必须设置为all,这样才可以将所有的值匹配到,并将其保存在一个数组中。*/ //这是航班的关联函数
web_reg_save_param_ex(
"ParamName=fligthno",
"LB=outboundFlight value=",
"RB=;",
"Ordinal=all",
SEARCH_FILTERS,
LAST); //这是票价的关联函数
web_reg_save_param_ex(
"ParamName=fligthcost",
"LB=center>$",
"RB=</TD>",
"Ordinal=all",
SEARCH_FILTERS,
LAST);
/*设置一个标记flag来保存票价*/ //初始化最贵机票,将第一个航班的机票设置为初始化的最贵的机票
max = atoi(lr_eval_string ("{wcsparam_text1_1}"));
//初始化标识位,默认设置为1
flagno=;
//for循环所有机票
for (i=;i<=atoi(lr_eval_string ("{wcsparam_text1_count}"));i++) {
sprintf(cost,"{wcsparam_text1_%d}",i);
//比较最前航班的机票是否大于max的值,如果大于max的值,即重新对max赋值
if(atoi(lr_eval_string (cost))>max){
max=atoi(lr_eval_string (cost));
flagno=i;
}
} /*找到最便宜的机票后,可以得到该数组的下标,那这个数组的下标所对应的航班就是票价最便宜的航班,获取航班号的代码如下:*/ //通过标识位来确定航班
sprintf(flightelem,
"{wcsparam_text2_%d}",
flagno);
lr_save_string (lr_eval_string (flightelem),
"fligthno"); web_submit_data("reservations.pl_2",
"Action=http://127.0.0.1:1080/WebTours/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",
"Snapshot=t25.inf",
"Mode=HTTP",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value=Denver", ENDITEM,
"Name=departDate", "Value=04/11/2017", ENDITEM,
"Name=arrive", "Value=London", ENDITEM,
"Name=returnDate", "Value=04/12/2017", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatPref", "Value=Window", ENDITEM,
"Name=seatType", "Value=First", ENDITEM,
"Name=.cgifields", "Value=roundtrip", ENDITEM,
"Name=.cgifields", "Value=seatType", ENDITEM,
"Name=.cgifields", "Value=seatPref", ENDITEM,
"Name=findFlights.x", "Value=48", ENDITEM,
"Name=findFlights.y", "Value=10", ENDITEM,
LAST); lr_think_time(); /*获得最便宜的票价和航班后,即将这两部分的信息放入到提交的信息中,作为客户端的请求进行提交即可,具体代码如下*/
web_submit_data("reservations.pl_3",
"Action=http://127.0.0.1:1080/WebTours/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=t26.inf",
"Mode=HTTP",
ITEMDATA,
//"Name=outboundFlight", "Value=023;519;04/11/2017", ENDITEM,
"Name=outboundFlight", "Value={flightno};{flightnocost};04/11/2017", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=seatType", "Value=First", ENDITEM,
"Name=seatPref", "Value=Window", ENDITEM,
"Name=reserveFlights.x", "Value=43", ENDITEM,
"Name=reserveFlights.y", "Value=6", ENDITEM,
LAST); web_submit_data("reservations.pl_4",
"Action=http://127.0.0.1:1080/WebTours/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=t27.inf",
"Mode=HTTP",
ITEMDATA,
"Name=firstName", "Value=test1", ENDITEM,
"Name=lastName", "Value=test1", ENDITEM,
"Name=address1", "Value=", ENDITEM,
"Name=address2", "Value=", ENDITEM,
"Name=pass1", "Value=test1 test1", ENDITEM,
"Name=creditCard", "Value=", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=oldCCOption", "Value=", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatType", "Value=First", ENDITEM,
"Name=seatPref", "Value=Window", ENDITEM,
//"Name=outboundFlight", "Value=023;519;04/11/2017", ENDITEM,
"Name=outboundFlight", "Value={flightno};{flightnocost};04/11/2017", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=returnFlight", "Value=", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=.cgifields", "Value=saveCC", ENDITEM,
"Name=buyFlights.x", "Value=48", ENDITEM,
"Name=buyFlights.y", "Value=6", ENDITEM,
LAST); web_url("bookanother.gif",
"URL=http://127.0.0.1:1080/WebTours/images/bookanother.gif",
"Resource=1",
"RecContentType=image/gif",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=t28.inf",
LAST); lr_end_transaction("订票", LR_AUTO); return ;
}
附上航班信息源码:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Flight Selections</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body bgcolor="#E0E7F1">
<style>blockquote {font-family: tahoma; font-size : 10pt}H1 {font-family: tahoma; font-size : 22pt; color: #}small {font-family: tahoma; font-size : 8pt}H3 {font-family: tahoma; font-size : 10pt; color: black}TD {font-family: tahoma; font-size : 10pt; color: black}</style><BR><BR><h1><font color=#> <b>Find Flight</font></b></h1><blockquote>
<form method="post" action="reservations.pl" enctype="application/x-www-form-urlencoded"> <center>
<!-- From Denver () To London () -->
<table cellspacing= border= width=%>
<blockquote>Flight departing from <B>Denver</B> to <B>London</B> on <B>//</B><BR><BR><tr bgcolor=#5E7884><td align=center><font color=white><B>Flight</B></font>
<td align=center><font color=white><B>Departure time</B>
<td align=center><font color=white><B>Cost</B>
//从下面可以看出航班(020、021...)的 左边界是 outboundFlight value= 右边界是 ;
// 票价($ 635、$ 565...)的 左边界是 center>$ 右边界是 </TD>
<tr bgcolor=#EFF2F7>
<td align=center><input type = radio name=outboundFlight value=;;// checked >Blue Sky Air <td align=center>8am<td align=center>$ </TD>
</TR>
<tr bgcolor=#EFF2F7>
<td align=center><input type = radio name=outboundFlight value=;;//>Blue Sky Air <td align=center>1pm<td align=center>$ </TD>
</TR>
<tr bgcolor=#EFF2F7>
<td align=center><input type = radio name=outboundFlight value=;;//>Blue Sky Air <td align=center>5pm<td align=center>$ </TD>
</TR>
<tr bgcolor=#EFF2F7>
<td align=center><input type = radio name=outboundFlight value=;;//>Blue Sky Air <td align=center>11pm<td align=center>$ </TD>
</TR>
</table> <input type="hidden" name="numPassengers" value="" /><input type="hidden" name="advanceDiscount" value="" /><input type="hidden" name="seatType" value="First" /><input type="hidden" name="seatPref" value="Window" />
<P><center><table width=% cellspacing=><tr><td align=center>
<input type="image" name="reserveFlights" src="/WebTours/images/button_next.gif" border="" />
<td> <td align=center></table></center></form></center>
</blockquote> </body>
</html>
航班信息
loadrunner提高篇 - 关联技术的经典使用的更多相关文章
- loadrunner提高篇-插入检查点与关联函数
插入检查点 靠LR自动生成的脚本是不够的,很难达到业务要求,因此需要对录制完的脚本进行完善,使其能达到业务模拟的要求 ,这样尽可能地使虚拟用户模拟时更接近用户的实际使用. 在进行压力测试时,经常会 ...
- loadrunner提高篇-block(块)技术和参数化
Block(块)技术 block(块)技术是应用于在一个脚本中实现不同事务.不同次数循环或不同百分比循环的情况.比如在一个脚本中,登录执行3次,查询执行1次. 使用方法如下: 1.录制一个脚本,包含2 ...
- loadrunner提高篇-场景设计实践
集合点设置 一.为什么要进行集合点设置? 因为在测试过程中,并不能保证所有的Vuser都在同一时刻进行操作,这样就达不到并发测试的目的,故需要用到集合点技术,集合点的意思是如果在一个操作之前设置了一个 ...
- loadrunner提高篇-结果分析实践
分析图合并 一.分析图合并原理 选择view->merge graphs,弹出如图1所示对话框 图1(设置合并图) 1.选择要合并的图.选择一个要与当前活动图合并的图,注意这里只能选择X轴度量单 ...
- 【Loadrunner】Loadrunner 手动关联技术
Loadrunner 手动关联技术 录制成功,回放失败,怀疑和动态数据有关: 1 重新录制一份脚本,两次录制的脚本进行比对,确定动态数据,复制动态数据: 2 找到第一次产生该动态数据的响应对应的相应 ...
- LoadRunner脚本篇
LoadRunner脚本篇 1概述 2脚本录制 3脚本编写 4脚本调试 关 键 词:LoadRunner 性能测试脚本 摘 要:编写一个准确无误的脚本对性能测试有至关重要的意 ...
- java提高篇(八)----详解内部类
可以将一个类的定义放在另一个类的定义内部,这就是内部类. 内部类是一个非常有用的特性但又比较难理解使用的特性(鄙人到现在都没有怎么使用过内部类,对内部类也只是略知一二). 第一次见面 内部类我们从外面 ...
- java提高篇(四)-----理解java的三大特性之多态
面向对象编程有三大特性:封装.继承.多态. 封装隐藏了类的内部实现机制,可以在不影响使用的情况下改变类的内部结构,同时也保护了数据.对外界而已它的内部细节是隐藏的,暴露给外界的只是它的访问方法. 继承 ...
- java提高篇(二)-----理解java的三大特性之继承
在<Think in java>中有这样一句话:复用代码是Java众多引人注目的功能之一.但要想成为极具革命性的语言,仅仅能够复制代码并对加以改变是不够的,它还必须能够做更多的事情.在这句 ...
随机推荐
- 【转载】Apache Jena TDB CRUD operations
Apache Jena TDB CRUD operations June 11, 2015 by maltesander http://tutorial-academy.com/apache-jena ...
- 创建jsp+Servlet+JavaBean+JDBC+MySQL项目的过程
1 根据需求建立Mysql数据,确立数据库的表的字段.属性.主键,外键等.下面我使用的数据库名dev ,表名user,字段 name,设置为主键.用户名不能为空,字段password,密码 2 在E ...
- [故障引起的故事]URL中带加号的处理
问题起因: 客户订购了一关键字为"e+h 变送器" , 在首页推荐广告中,会根据用户在search 搜索过的关键字进行一个匹配投放.技术实现是UED 通过JS 获取coo ...
- 吴裕雄 数据挖掘与分析案例实战(2)——python数据结构及方法、控制流、字符串处理、自定义函数
list1 = ['张三','男',33,'江苏','硕士','已婚',['身高178','体重72']]# 取出第一个元素print(list1[0])# 取出第四个元素print(list1[3] ...
- avg(xxxxxx)什么时候能独自出现?
avg(xxxxxx)是作为求一组数据的平均数,需要有这组数据的总数和个数,所以通常配合着group by来使用, 比如: SELECT ID, AVG(GRADE) AS 平均数 FROM TEST ...
- leetcode 183. Customers Who Never Order
select Name as Customers from Customers where Id not in (select CustomerId from Orders);
- day12:vcp考试
Q221. An administrator is creating a new Platform Service Controller Password Policy with the follow ...
- 关于swift语言中导入OC三方类找不到头文件的解决方法
首先我遇到的问题是这样的: 我之前封装的OC类,我导入现在的swift工程中,然后建立桥接文件,在Swift的控制器中可以找到这个OC写的东西. 但是问题来了,当你使用cocoapods导入的OC三方 ...
- AspectJ的XML方式完成AOP的开发之切入点的表达式
1. 再配置切入点的时候,需要定义表达式,重点的格式如下:execution(public * *(..)),具体展开如下: * 切入点表达式的格式如下: * execution([修饰符] 返回值类 ...
- DataTableExtensions
public static class DataTableExtensions { public static List<dynamic> ToDynamic(this DataTable ...