百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

性能测试之看懂这一个LoadRunner再无困难的脚本

cac55 2024-09-26 07:28 16 浏览 0 评论

一个特别的练习需求

LoadRunner自带的训练的飞机票网站的例子中,有一个很有意思的流程,如下:首先登陆机票系统,然后查询从哪里到哪里的机票。然后系统会给你4张推荐票。选择一张机票,后就可以支付然后完成机票的预定和购买了。

我相信所有在用LoadRunner的人对这个流程都不陌生,很熟悉。那么今天测者提出一个问题,我想一个脚本购买推荐的4张飞机票。该如何处理对应的测试脚本呢?

一个飞机票的超级脚本

Action()

{

int i=0;//循环订票的游标变量

char temp[255];//临时存储字符串变量

int count=0;//存储循环关联数组长度变量

char tempfly[255];//临时存储字符串变量

web_url("WebTours",

"URL=http://127.0.0.1:1080/WebTours/",

"Resource=0",

"RecContentType=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=HTTP",

LAST);

web_concurrent_start(NULL);

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=t2.inf",

"Mode=HTTP",

LAST);

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=t4.inf",

"Mode=HTTP",

LAST);

web_concurrent_end(NULL);

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=t3.inf",

LAST);

web_url("webtours.png",

"URL=http://127.0.0.1:1080/WebTours/images/webtours.png",

"Resource=1",

"RecContentType=image/png",

"Referer=http://127.0.0.1:1080/WebTours/header.html",

"Snapshot=t5.inf",

LAST);

web_concurrent_end(NULL);

web_concurrent_start(NULL);

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=t6.inf",

"Mode=HTTP",

LAST);

web_reg_save_param("sessionuser","LB=<input type=hidden name=userSession value=","RB=>",LAST);//获取用于session值的关联函数

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_concurrent_end(NULL);

web_concurrent_start(NULL);

web_url("JSFormSubmit.js",

"URL=http://127.0.0.1:1080/WebTours/JSFormSubmit.js",

"Resource=1",

"RecContentType=application/x-javascript",

"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

"Snapshot=t8.inf",

LAST);

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_end(NULL);

lr_start_transaction("login-0");

lr_think_time(9);

lr_error_message("sessionuser:%s",lr_eval_string("{sessionuser}"));//打印关联到的用户session值

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=t10.inf",

"Mode=HTTP",

ITEMDATA,

"Name=userSession", "Value={sessionuser}", ENDITEM,

"Name=username", "Value=test001", ENDITEM,

"Name=password", "Value=123456", ENDITEM,

"Name=JSFormSubmit", "Value=on", ENDITEM,

"Name=login.x", "Value=64", 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=t11.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=t16.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=t12.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=t13.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=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_concurrent_end(NULL);

lr_end_transaction("login-0",LR_AUTO);

lr_start_transaction("book-1");

lr_think_time(11);

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=t17.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=t18.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=t19.inf",

"Mode=HTTP",

LAST);

web_concurrent_end(NULL);

web_concurrent_start(NULL);

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=t20.inf",

LAST);

web_url("itinerary.gif_2",

"URL=http://127.0.0.1:1080/WebTours/images/itinerary.gif",

"Resource=0",

"RecContentType=text/html",

"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

"Mode=HTTP",

LAST);

web_url("signoff.gif_2",

"URL=http://127.0.0.1:1080/WebTours/images/signoff.gif",

"Resource=0",

"RecContentType=text/html",

"Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

"Mode=HTTP",

LAST);

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=t21.inf",

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_reg_save_param("flytype","LB=<input type = radio name=outboundFlight value=","RB=>","ORD=ALL","Savelen=18",LAST);//关联取得出现的4张电子机票

// web_reg_save_param("seatPref","LB=<input type=\"radio\" name=\"seatPref\" value=\"","RB=\" ","ORD=ALL","SaveLen=6",LAST);

// web_reg_save_param("seatType","LB=<input type=\"radio\" name=\"seatType\" value=\"","RB=\" ","ORD=ALL","SaveLen=8",LAST);

lr_error_message("seatPref_1:",lr_eval_string("{seatPref_1}"));

lr_error_message("seatPref_2:",lr_eval_string("{seatPref_2}"));

lr_error_message("seatPref_3:",lr_eval_string("{seatPref_3}"));

lr_error_message("seatType_1:",lr_eval_string("{seatType_1}"));

lr_error_message("seatType_2:",lr_eval_string("{seatType_2}"));

lr_error_message("seatType_3:",lr_eval_string("{seatType_3}"));

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=t23.inf",

"Mode=HTTP",

ITEMDATA,

"Name=advanceDiscount", "Value=0", ENDITEM,

"Name=depart", "Value=Denver", ENDITEM,

"Name=departDate", "Value=05/29/2013", ENDITEM,

"Name=arrive", "Value={endplace}", ENDITEM,

"Name=returnDate", "Value=05/30/2013", ENDITEM,

"Name=numPassengers", "Value=1", ENDITEM,

"Name=seatPref", "Value={seatPerf}", ENDITEM,

"Name=seatType", "Value={seatType}", ENDITEM,

"Name=.cgifields", "Value=roundtrip", ENDITEM,

"Name=.cgifields", "Value=seatType", ENDITEM,

"Name=.cgifields", "Value=seatPref", ENDITEM,

"Name=findFlights.x", "Value=80", ENDITEM,

"Name=findFlights.y", "Value=15", ENDITEM,

LAST);

lr_error_message("seatPerf:%s",lr_eval_string("{seatPerf}"));

lr_error_message("seatType:%s",lr_eval_string("{seatType}"));

count = atoi(lr_eval_string("{flytype_count}"));

lr_error_message("lenflytype:%d",count);

lr_error_message("Flytype_1:%s",lr_eval_string("{flytype_1}"));

lr_error_message("Flytype_2:%s",lr_eval_string("{flytype_2}"));

lr_error_message("Flytype_3:%s",lr_eval_string("{flytype_3}"));

lr_error_message("Flytype_4:%s",lr_eval_string("{flytype_4}"));

for(i=0;i<count;i++)

{

sprintf(temp,"{flytype_%d}",i+1);//格式化flytype数组参数格式,取数组中一个存入temp变量

lr_error_message("temp:%s",temp);//打印temp变量的内容

sprintf(tempfly,"%s",lr_eval_string(temp));//将temp变量通过lr_eval_string函数将temp变量存储的对应loadrunner参数的对应内容存入tempfly变量中

lr_error_message("tempfly:%s",tempfly);//打印tempfly变量的内容

lr_error_message("lr_eval_string(tempfly):%s",lr_eval_string(tempfly));//通过lr_eval_string函数取得tempfly变量的内容

lr_save_string(tempfly,"flytypenum");//将tempfly变量内容存到flytypenum参数中,方便以后lr函数使用

lr_error_message("flytypenum:%s",lr_eval_string("{flytypenum}"));//打印flytypenum内容

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=t24.inf",

"Mode=HTTP",

ITEMDATA,

"Name=outboundFlight", "Value={flytypenum}", ENDITEM,

"Name=numPassengers", "Value=1", ENDITEM,

"Name=advanceDiscount", "Value=0", ENDITEM,

"Name=seatType", "Value=Coach", ENDITEM,

"Name=seatPref", "Value=None", ENDITEM,

"Name=reserveFlights.x", "Value=63", ENDITEM,

"Name=reserveFlights.y", "Value=17", 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=t25.inf",

"Mode=HTTP",

ITEMDATA,

"Name=firstName", "Value=test001", ENDITEM,

"Name=lastName", "Value=test001", ENDITEM,

"Name=address1", "Value=test001", ENDITEM,

"Name=address2", "Value=123456", ENDITEM,

"Name=pass1", "Value=test001 test001", ENDITEM,

"Name=creditCard", "Value=", ENDITEM,

"Name=expDate", "Value=", ENDITEM,

"Name=oldCCOption", "Value=", ENDITEM,

"Name=numPassengers", "Value=1", ENDITEM,

"Name=seatType", "Value=Coach", ENDITEM,

"Name=seatPref", "Value=None", ENDITEM,

"Name=outboundFlight", "Value={flytypenum}", ENDITEM,

"Name=advanceDiscount", "Value=0", ENDITEM,

"Name=returnFlight", "Value=", ENDITEM,

"Name=JSFormSubmit", "Value=off", ENDITEM,

"Name=.cgifields", "Value=saveCC", ENDITEM,

"Name=buyFlights.x", "Value=61", ENDITEM,

"Name=buyFlights.y", "Value=8", 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=t26.inf",

LAST);

lr_end_transaction("book-1",LR_AUTO);

return 0;

}

特别点的解释

首先,LoadRunner是类C语言,因此变量要放到函数的开头声明(C语言的变量)。其次,在for循环中,我们看到了几次sprintf,那么这里了测者会详细说一下,第一次 (假设当前i=0), sprintf(temp,"{flytype_%d}",i+1);,其中“{flytype1}”的含义(包含双引号),是将一个指向了存有flytype_1值的内存地址的指针指向的值赋值给了temp。也就是temp指向了一段存储了fltype_1值的内存。sprintf(tempfly,"%s",lrevalstring(temp));将flytype_1这个指针指向的内存地址存储的值赋给了tempfly,也就是说tempfly和flytype_1这两个指针都指向相同内存地址,这段地址存储的就是关联出来的第一张机票的ouboundFlight值。

————————————————————————————————————————————————

给大家推荐一个学习资料分享群(574253227),里面大牛已经为我们整理好了许多的学习资料,有自动化,接口,性能等等的学习资料!

相关推荐

远程桌面管理服务器的软件工具:Splashtop

通过远程控制和维护服务器,IT运维无需亲自在设备附近就可以轻松完成工作,极大地提高了效率。在本文中,我们将深入了解远程桌面管理服务器的主要优点,以及实现此任务所需的软件工具和操作方法。首先,远程桌面管...

最担心的事还是发生了 19岁黑客远程破解逾25台特斯拉

近日,德国19岁的安全研究人员大卫·科伦坡(DavidColombo)表示,他在特斯拉的系统中发现一处系统漏洞,并通过该漏洞远程入侵了13个国家的25辆特斯拉电动汽车,使其关闭安全系统。他几乎掌控了...

朝鲜黑客使用已知恶意软件家族FASTCash的 Linux 变种来窃取资金

据观察,朝鲜威胁组织使用已知恶意软件家族FASTCash的Linux变种来窃取资金,作为以财务为动机的活动的一部分。一位自称HaxRob的安全研究员表示,这种恶意软件“安装在受感染网络内处理卡...

Phorpiex恶意脚本卷土重来,成为LockBit 3.0勒索木马传播载体

IT之家5月5日消息,安全公司Cybereason发文透露“老牌”恶意脚本Phorpiex近日又卷土重来,成为传播LockBit3.0勒索木马的载体,感染了相应脚本的设备会自动下...

黑客远程入侵控制Jeep 自由光 互联网汽车存隐患

当我们在为汽车互联网技术带来的便捷欢呼雀跃时,也许危险也在悄悄走近。近日据Wired报道,名叫安迪的男子正开着Jeep自由光以70码的时速行驶在圣路易斯下城区时,车辆突然失去了控制。“首先是冷风突然调...

警惕!KeePass密码管理器竟成黑客“帮凶”

近日,网络安全领域爆出一则令人震惊的消息:网络安全公司WithSecure披露,在过去至少八个月的时间里,黑客通过篡改知名的KeePass密码管理器,上演了一场大规模的恶意攻击大戏!KeePass作...

开源网页应用框架ThinkPHP遭黑客滥用,变身远程代码执行工具

IT之家6月9日消息,安全公司Akamai近日发布报告,声称目前有黑客滥用一款热门开源网页应用框架ThinkPHP中的远程执行代码漏洞,打造了一款名为“Dama”的恶意工具进行攻击。I...

远程控制、窃密、挖矿!我国境内捕获“银狐”木马病毒变种

最近大家可得小心电脑病毒了!国家相关部门刚通报了一个叫"银狐"的木马病毒新变种,专门盯着普通老百姓和企事业单位下手。我给大家掰开揉碎了讲讲,遇到这种情况该怎么躲坑?·一、这病毒怎么盯上...

6款Linux常用远程连接工具,你最中意哪一款?

点击上方头像关注我,每周上午09:00准时推送,每月不定期赠送技术书籍。本文2106字,阅读约需6分钟Hi,大家好。远程连接的实现方法有很多,概括地说有两种,一种是用系统自带的远程连接,另外一种是用...

安全公司曝光黑客山寨杀毒软件Bitdefender官网,实为提供木马

IT之家5月31日消息,安全公司DomainTools发文,透露有黑客伪造网站声称提供杀毒软件,实则借机传播恶意木马。IT之家参考相应通报获悉,相应黑客首先建立山寨Bitdefender...

魔兽世界怀旧服:mc与bwl高手进阶输出手法与职业心得理解

作者:NGA-499917309a前言:之前写了两篇教新手术士怎么打mc和bwl的帖子,属于基础入门,只是让大家会打,随着时间推移,副本早已进入farm阶段,新手也不满足于会打,而是追求更高的输出,甚...

《奇幻梦境》进不去游戏解决方法攻略

奇幻梦境第一章近日发售了,本作也是一款第一人称解密游戏。本作的游戏画面色彩简单明了,包括了游戏的剧情也是。有不少的小伙伴反映奇幻梦境打不开不进不去,接下来小编就给大家解决这款游戏打不开进不去的一些可能...

国外网友热议:LOL客户端仍然如此差劲!新版又在测试了?

印象中英雄联盟的客户端换过几次版本,但是动作最大的应该就是在2017年的那次,直接更换了整个客户端的UI界面以及内部的很多组件。但是新版客户端上线至今两年多的时间里,玩家对于这个客户端的吐槽依旧很多,...

谷歌地球免费专业版7.1.5.1557下载

IT之家讯5月22日消息,谷歌地球专业版GoogleEarthPro已经更新到7.1.5.1557版,目前,谷歌官方还没有给出更新日志。这种情况通常来讲都是常规问题修复,建议新老用户及时下载安装...

僵尸部队三部曲 免安装中文硬盘版下载发布

【游戏封面】中文名称:僵尸部队三部曲游戏名称:ZombieArmytrilogy游戏类型:第三人称射击游戏制作:Rebellion游戏发行:Rebellion游戏发行:PC游民星空狙击精英3专区版...

取消回复欢迎 发表评论: