loadrunner检查点(代码片段)

pythonstart pythonstart     2022-11-15     212

关键词:

loadrunner帮助文档给的示例:
Example 2 is the same as example 1, but because Save Count is used, the script execution is not halted on failure. Instead, the error is handled in the code.

    // Run the Web Tours sample

    web_url("MercuryWebTours",

        "URL=http://localhost/MercuryWebTours/",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=",

        "Snapshot=t1.inf",

        "Mode=HTML",

        LAST );

// Set up check for successful login by looking for "Welcome"

    web_reg_find("Text=Welcome",

        "SaveCount=Welcome_Count",

        LAST );

// Now log in

    web_submit_form("login.pl",

        "Snapshot=t2.inf",

        ITEMDATA,

        "Name=username", "Value=jojo", ENDITEM,

        "Name=password", "Value=bean", ENDITEM,

        "Name=login.x", "Value=35", ENDITEM,

        "Name=login.y", "Value=14", ENDITEM,

        LAST );

// Check result

    if (atoi(lr_eval_string("Welcome_Count")) > 0)

        lr_output_message("Log on successful.");

       

     else

        lr_error_message("Log on failed");

        return(0);

    



注册提交的脚本:

submit()
//int registercount = 0; web_reg_find("Search=Body", "SaveCount=registerflag",, "Text=Thank you, <b>username</b>",//此处检查的是服务器返回的内容,而不是展示的内容,当去掉<b></b>标签后,无法检查到内容,运行结果是失败的 LAST); lr_think_time(5); web_submit_data("login.pl_2", "Action=http://127.0.0.1:1080/cgi-bin/login.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/cgi-bin/login.pl?username=&password=&getInfo=true", "Snapshot=t7.inf", "Mode=HTML", ITEMDATA, "Name=username", "Value=username", ENDITEM, "Name=password", "Value=123", ENDITEM, "Name=passwordConfirm", "Value=123", ENDITEM, "Name=firstName", "Value=", ENDITEM, "Name=lastName", "Value=", ENDITEM, "Name=address1", "Value=", ENDITEM, "Name=address2", "Value=", ENDITEM, "Name=register.x", "Value=45", ENDITEM, "Name=register.y", "Value=11", ENDITEM, LAST); //registercount = atoi(lr_eval_string("registerflag")); if(atoi(lr_eval_string("registerflag")) > 0) lr_output_message("注册成功"); else lr_output_message("注册失败,错误的账号是:%s",lr_eval_string("username")); return 0;
atoi(lr_eval_string("registerflag 返回结果是一个数,通过atoi函数将结果转换成int,可以将注释的去掉,if(registercount > 0)也可以有同样效果。
执行过程中多次脚本不报错,但实际结果与运行结果不一致,可以适当手动重复步骤,然后通过浏览器查看源文件可以查看到检查点周围是否有在浏览器界面不展示的信息。
web_reg_find()函数是一个注册函数,需要写在检查内容前面。判断语句写在后面。


添加了<b></b>标签的运行结果日志:提示消息正确,账号注册成功
Starting action vuser_init.
Web Turbo Replay of LoadRunner 12.0.0 for Windows 7; build 2079 (Jun 17 2014 10:56:12)      [MsgId: MMSG-27143]
Run mode: HTML      [MsgId: MMSG-26993]
Run-Time Settings file: "D:\lrtest\lrregister\lr-register\\default.cfg"      [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Maximum number of concurrent connections per server: 6      [MsgId: MMSG-26989]
Starting action openurl.
openurl.c(4): web_url("index.htm") started      [MsgId: MMSG-26355]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/WebTours/header.html" in "http://127.0.0.1:1080/WebTours/index.htm"      [MsgId: MMSG-26574]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/cgi-bin/welcome.pl?signOff=true" in "http://127.0.0.1:1080/WebTours/index.htm"      [MsgId: MMSG-26574]
openurl.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/hp_logo.png" in HTML "http://127.0.0.1:1080/WebTours/header.html"      [MsgId: MMSG-26659]
openurl.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/webtours.png" in HTML "http://127.0.0.1:1080/WebTours/header.html"      [MsgId: MMSG-26659]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/cgi-bin/nav.pl?in=home" in "http://127.0.0.1:1080/cgi-bin/welcome.pl?signOff=true"      [MsgId: MMSG-26574]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/WebTours/home.html" in "http://127.0.0.1:1080/cgi-bin/welcome.pl?signOff=true"      [MsgId: MMSG-26574]
openurl.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/mer_login.gif" in HTML "http://127.0.0.1:1080/cgi-bin/nav.pl?in=home"      [MsgId: MMSG-26659]
openurl.c(4): web_url("index.htm") was successful, 10080 body bytes, 2371 header bytes, 24 chunking overhead bytes      [MsgId: MMSG-26385]
Ending action openurl.
Starting action registerinfo.
registerinfo.c(4): web_url("login.pl") started      [MsgId: MMSG-26355]
registerinfo.c(4): Found resource "http://127.0.0.1:1080/WebTours/profileValidate.js" in HTML "http://127.0.0.1:1080/cgi-bin/login.pl?username=&password=&getInfo=true"      [MsgId: MMSG-26659]
registerinfo.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/button_next.gif" in HTML "http://127.0.0.1:1080/cgi-bin/login.pl?username=&password=&getInfo=true"      [MsgId: MMSG-26659]
registerinfo.c(4): web_url("login.pl") was successful, 14475 body bytes, 838 header bytes, 12 chunking overhead bytes      [MsgId: MMSG-26385]
Ending action registerinfo.
Starting action submit.
submit.c(5): web_reg_find started      [MsgId: MMSG-26355]
submit.c(5): Notify: Parameter Substitution: parameter "username" =  "test1"
submit.c(5): Registering web_reg_find was successful      [MsgId: MMSG-26390]
submit.c(14): web_submit_data("login.pl_2") started      [MsgId: MMSG-26355]
submit.c(14): Notify: Parameter Substitution: parameter "username" =  "test1"
submit.c(14): Resource "http://127.0.0.1:1080/WebTours/images/button_next.gif" is in the cache already and will not be downloaded again      [MsgId: MMSG-26655]
submit.c(14): Registered web_reg_find successful for "Text=Thank you, <b>test1</b>" (count=1)      [MsgId: MMSG-26364]
submit.c(14): Notify: Saving Parameter "registerflag = 1".
submit.c(14): web_submit_data("login.pl_2") was successful, 1078 body bytes, 345 header bytes, 12 chunking overhead bytes      [MsgId: MMSG-26385]
submit.c(34): Notify: Parameter Substitution: parameter "registerflag" =  "1"
submit.c(35): 注册成功
Ending action submit.


未添加了<b></b>标签的运行结果日志:提示消息错误,账号实际是注册成功的。

Virtual User Script started at : 2018/5/22 10:46:51
Starting action vuser_init.
Web Turbo Replay of LoadRunner 12.0.0 for Windows 7; build 2079 (Jun 17 2014 10:56:12)      [MsgId: MMSG-27143]
Run mode: HTML      [MsgId: MMSG-26993]
Run-Time Settings file: "D:\lrtest\lrregister\lr-register\\default.cfg"      [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Maximum number of concurrent connections per server: 6      [MsgId: MMSG-26989]
Starting action openurl.
openurl.c(4): web_url("index.htm") started      [MsgId: MMSG-26355]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/WebTours/header.html" in "http://127.0.0.1:1080/WebTours/index.htm"      [MsgId: MMSG-26574]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/cgi-bin/welcome.pl?signOff=true" in "http://127.0.0.1:1080/WebTours/index.htm"      [MsgId: MMSG-26574]
openurl.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/hp_logo.png" in HTML "http://127.0.0.1:1080/WebTours/header.html"      [MsgId: MMSG-26659]
openurl.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/webtours.png" in HTML "http://127.0.0.1:1080/WebTours/header.html"      [MsgId: MMSG-26659]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/cgi-bin/nav.pl?in=home" in "http://127.0.0.1:1080/cgi-bin/welcome.pl?signOff=true"      [MsgId: MMSG-26574]
openurl.c(4): Detected non-resource "http://127.0.0.1:1080/WebTours/home.html" in "http://127.0.0.1:1080/cgi-bin/welcome.pl?signOff=true"      [MsgId: MMSG-26574]
openurl.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/mer_login.gif" in HTML "http://127.0.0.1:1080/cgi-bin/nav.pl?in=home"      [MsgId: MMSG-26659]
openurl.c(4): web_url("index.htm") was successful, 10076 body bytes, 2371 header bytes, 24 chunking overhead bytes      [MsgId: MMSG-26385]
Ending action openurl.
Starting action registerinfo.
registerinfo.c(4): web_url("login.pl") started      [MsgId: MMSG-26355]
registerinfo.c(4): Found resource "http://127.0.0.1:1080/WebTours/profileValidate.js" in HTML "http://127.0.0.1:1080/cgi-bin/login.pl?username=&password=&getInfo=true"      [MsgId: MMSG-26659]
registerinfo.c(4): Found resource "http://127.0.0.1:1080/WebTours/images/button_next.gif" in HTML "http://127.0.0.1:1080/cgi-bin/login.pl?username=&password=&getInfo=true"      [MsgId: MMSG-26659]
registerinfo.c(4): web_url("login.pl") was successful, 14475 body bytes, 838 header bytes, 12 chunking overhead bytes      [MsgId: MMSG-26385]
Ending action registerinfo.
Starting action submit.
submit.c(5): web_reg_find started      [MsgId: MMSG-26355]
submit.c(5): Notify: Parameter Substitution: parameter "username" =  "test1"
submit.c(5): Registering web_reg_find was successful      [MsgId: MMSG-26390]
submit.c(13): web_submit_data("login.pl_2") started      [MsgId: MMSG-26355]
submit.c(13): Notify: Parameter Substitution: parameter "username" =  "test1"
submit.c(13): Resource "http://127.0.0.1:1080/WebTours/images/button_next.gif" is in the cache already and will not be downloaded again      [MsgId: MMSG-26655]
submit.c(13): Registered web_reg_find successful for "Text=Thank you, test1"      [MsgId: MMSG-26362]
submit.c(13): Notify: Saving Parameter "registerflag = 0".
submit.c(13): web_submit_data("login.pl_2") was successful, 1078 body bytes, 345 header bytes, 12 chunking overhead bytes      [MsgId: MMSG-26385]
submit.c(33): Notify: Parameter Substitution: parameter "registerflag" =  "0"
submit.c(36): Notify: Parameter Substitution: parameter "username" =  "test1"
submit.c(36): 注册失败,错误的账号是:test1
Ending action submit.
Ending iteration 1.
 
 
 

软件测试性能测试工具基础-loadrunner12+jmeter(代码片段)

...本使用1、创建工程2、录制脚本3、回放脚本4、增强脚本1)检查点(断言)2)读取参数、输出函数以及自定义变量3)事务4)参数化5)关联6)集合点7)block块技 查看详情

loadrunner文本中怎么添加检查点

参考技术Aloadrunner添加检查点函数步骤:1、做为例子,首先使用录制的方式,把论坛的代码编写完成后,要判断的执行前插入检查点,使用右键方式,弹出的下拉的菜单中进行选择“insert”的选项。2、就在弹出下一级的菜单中... 查看详情

loadrunner之二“集合点”(代码片段)

...面加入集合点,当虚拟用户运行到提交数据的集合点时,LoadRunner 就会检查同时有多少用户运行到集合点,如果不到1000 人,LoadRunner 就会命令已经到集合点的用户在此等待,当在集合点等待的用户达到1000 人时,Lo... 查看详情

loadrunner性能测试入门流程(代码片段)

大家好,欢迎大家步入loadrunner的课堂,在学习Loadrunner的过程中可能会遇到很多问题和报错,不要灰心,多去找找解决方法,经过解决才能真正学习并且领悟很多知识,话不多说,开启我们loadrunner的入门课程1.Loadrunner的介绍1.是HP(Mercury)公... 查看详情

loadrunner脚本编写(代码片段)

...试工程师要懂代码么?答案是必须的。好多测试员认为在loadrunner中编写脚本很难很牛X ,主要是大多测试人员并未做过开发工作,大学的那点程序基础也忘记的差不多了。还有非计算机专业出身的测试员,所以对代码望都比较... 查看详情

loadrunner例子:检查点为参数的一个例子

LoadRunner例子:检查点为参数的一个例子     检查点是LoadRunner的一个功能,用来验证业务功能的正确性。如果检查的内容是变化的,脚本该如何写呢?    问题提出:LoadRunner订票网站例子中,创建... 查看详情

loadrunner检查点使用

Loadrunner检查点使用web_find()函数该函数的作用是“在页面中查找相应的内容”,常用参数及含义如下:web_find("web_find",//定义该查找函数的名称"RightOf=a",//定义查找字符的右边界"LeftOf=b",//定义查找字符的... 查看详情

性能压测之loadrunner接口代码设计(代码片段)

笔者在进行Loadrunner压测时,编写http接口测试代码时,对于post请求常用到2个函数:?web_submit_data()?web_custom_request()现将性能代码分享如下:一、关于web_submit_data()函数web_reg_find("Text="success":true","SaveCount=spz_Count" 查看详情

loadrunner之检查点

一、什么是检查点  LoadRunner中检查点是用来判断脚本是否执行成功的。如果不加检查点,只要服务器返回的HTTP状态码是200,VuGen就认为脚本执行通过了。但是很多情况下服务器返回200并不代表脚本执行通过了,比如:登录操... 查看详情

loadrunner—关联(代码片段)

关联(correlation):简单来说就是将客户端发送请求后,服务器返回的动态数据信息保存到一个参数中。web_reg_save_param("login","LB=name=\"userSession\"value=\"","RB=\"/>",//双引号需要用反斜杠"\"进行转义LAST);基本信息: 1、web_reg_save_p... 查看详情

loadrunner三种post格式的请求(代码片段)

Loadrunner三种post格式的请求1web_custom_requestintweb_custom_request(constchar*RequestName,<ListofAttributes>,[EXTRARES,<ListofResourceAttributes>,]LAST);第一种:自定义http格式的请求,可以是任何的方式或是body如下:web_cus 查看详情

loadrunner上传文件到网盘(代码片段)

有人提问,loadrunner上传文件搞不好,请求帮忙处理。让提供网址,用fiddler抓包上传部分,主要有3个请求第一个请求GEThttps://yun.xxx.com/api/files/upload/request?groupid=406896460&parentid=0&size=10&name=ae.txt&parent_path=&checkna 查看详情

loadrunner中随机选取关联对象(代码片段)

我们在Loadrunner的测试过程中时常需要随机选择一个对象,进行下一步的操作,比如一个Table中有100行,测试的时候不能每次都选择同一行进行测试,而是要随机选择不同行,这样才能更好的模拟用户的真实情况第一步,找出返回... 查看详情

loadrunner检查点

  检查点最烦的就是检查不到,明明设置好了检查点,为什么检查不到呢?这篇不赘述检查点概念性东西,分享下我的纠结检查点之路。 1.什么是检查点?  检查点就是产品需求,测试要干的就是检查研发是否实现了产... 查看详情

loadrunner添加检查点

...         ——《可可西里》1、选择需要设置检查点的内容有如下“添加客户”功能,添加任务操作完成之后,我希望检查是否添加成功。从图中可以看出应用程序给出了“添加客户成功”的提示很遗憾的是当我选中... 查看详情

loadrunner添加检查点

1、系统登录成功后,添加检查点用来验证是否登录成功。2、脚本录制完之后,切换到,树(tree)视图,在需要添加检查点的步骤中,右键,选择在该步骤之前还是该在该步骤之后,   我要添加的检查点是“应用... 查看详情

第一次使用loadrunner时遇到的问题(代码片段)

记录一下第一次使用LoadRunner时遇到的问题安装LoadRunner下载链接:ed2k://|file|%5B%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95%E5%B7%A5%E5%85%B7LR11.00%5D.loadrunner-11.iso|4313382912|b95afeb3a879c6b8146435bb79e8cb97|h=nt 查看详情

loadrunner添加事务与参数化(代码片段)

 1.事务、计算单个请求的相应时间  添加事务(事务是可以嵌套的、但必须成对的)lr_start_transaction(‘openshouye‘)事务开始  lr_end_transaction(‘openshouye‘)事务结束lr_get_transaction_duration(‘openshouye‘)获取事务时间(包含浪费时... 查看详情