关联函数是一个查找函数,即是从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=#>&nbsp;&nbsp;<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>&nbsp;<td align=center></table></center></form></center>
</blockquote> </body>
</html>

航班信息

loadrunner提高篇 - 关联技术的经典使用的更多相关文章

  1. loadrunner提高篇-插入检查点与关联函数

    插入检查点   靠LR自动生成的脚本是不够的,很难达到业务要求,因此需要对录制完的脚本进行完善,使其能达到业务模拟的要求 ,这样尽可能地使虚拟用户模拟时更接近用户的实际使用. 在进行压力测试时,经常会 ...

  2. loadrunner提高篇-block(块)技术和参数化

    Block(块)技术 block(块)技术是应用于在一个脚本中实现不同事务.不同次数循环或不同百分比循环的情况.比如在一个脚本中,登录执行3次,查询执行1次. 使用方法如下: 1.录制一个脚本,包含2 ...

  3. loadrunner提高篇-场景设计实践

    集合点设置 一.为什么要进行集合点设置? 因为在测试过程中,并不能保证所有的Vuser都在同一时刻进行操作,这样就达不到并发测试的目的,故需要用到集合点技术,集合点的意思是如果在一个操作之前设置了一个 ...

  4. loadrunner提高篇-结果分析实践

    分析图合并 一.分析图合并原理 选择view->merge graphs,弹出如图1所示对话框 图1(设置合并图) 1.选择要合并的图.选择一个要与当前活动图合并的图,注意这里只能选择X轴度量单 ...

  5. 【Loadrunner】Loadrunner 手动关联技术

    Loadrunner 手动关联技术 录制成功,回放失败,怀疑和动态数据有关: 1 重新录制一份脚本,两次录制的脚本进行比对,确定动态数据,复制动态数据: 2  找到第一次产生该动态数据的响应对应的相应 ...

  6. LoadRunner脚本篇

    LoadRunner脚本篇     1概述 2脚本录制 3脚本编写 4脚本调试   关  键  词:LoadRunner 性能测试脚本 摘      要:编写一个准确无误的脚本对性能测试有至关重要的意 ...

  7. java提高篇(八)----详解内部类

    可以将一个类的定义放在另一个类的定义内部,这就是内部类. 内部类是一个非常有用的特性但又比较难理解使用的特性(鄙人到现在都没有怎么使用过内部类,对内部类也只是略知一二). 第一次见面 内部类我们从外面 ...

  8. java提高篇(四)-----理解java的三大特性之多态

    面向对象编程有三大特性:封装.继承.多态. 封装隐藏了类的内部实现机制,可以在不影响使用的情况下改变类的内部结构,同时也保护了数据.对外界而已它的内部细节是隐藏的,暴露给外界的只是它的访问方法. 继承 ...

  9. java提高篇(二)-----理解java的三大特性之继承

    在<Think in java>中有这样一句话:复用代码是Java众多引人注目的功能之一.但要想成为极具革命性的语言,仅仅能够复制代码并对加以改变是不够的,它还必须能够做更多的事情.在这句 ...

随机推荐

  1. eclipse 自动生成json格式的toString()方法

    文本代码 {"${member.name()}":"${member.value}", "${otherMembers}"}

  2. Haskell语言学习笔记(29)CPS

    CPS (Continuation Passing Style) CPS(延续传递风格)是指函数不把处理结果作为返回值返回而是把处理结果传递给下一个函数的编码风格. 与此相对,函数把处理结果作为返回值 ...

  3. Windows 2008开启远程桌面连接

    具体请看下面的截图. 最重要的就是要打开远程允许远程桌面的默认端口 3389 的入站规则,我第一次弄,这一端口没打开,折腾了很久!!! 第一.首先打开“服务器管理器”—“配置”—“高级安全Window ...

  4. Numpy数据存取

    Numpy数据存取 numpy提供了便捷的内部文件存取,将数据存为np专用的npy(二进制格式)或npz(压缩打包格式)格式 npy格式以二进制存储数据的,在二进制文件第一行以文本形式保存了数据的元信 ...

  5. python字符串填充(转)

    ljust()方法返回字符串左对齐的字符串长度宽度.填充是通过使用指定的fillchar(默认为空格).如果宽度小于len(s)返回原始字符串.语法 以下是ljust()方法的语法: str.ljus ...

  6. oracle 基本信息

    查看Oracle是32位还是64位的方法: 方法一:使用sqlplus 64位: [oracle@qs-wg-db2 ~]$ sqlplus / as sysdba;   SQL*Plus: Rele ...

  7. 【Java】JVM(二)、Java垃圾收集算法

    一.标记-清除算法 算法主要分为两个步骤 1. 标记: 遍历所有的 GC Roots, 然后标记所有可达对象为存活对象 2. 清除: 遍历堆中所有对象,然后将没有标记的对象清除. 存在不足: 1. 效 ...

  8. html中的innerHTML

    首先看个例子 <html> <head> <script type="text/javascript"> function getInnerHT ...

  9. TZOJ 1545 Hurdles of 110m(01背包dp)

    描述 In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperit ...

  10. TZOJ 4007 The Siruseri Sports Stadium(区间贪心)

    描述 The bustling town of Siruseri has just one sports stadium. There are a number of schools, college ...