loadRunner之接口测试
接口测试需求:
1、脚本支持循环测试,并且每次测试的请求报文不一样(字段stbId每次请求不一样)
2、输出每次测试的请求报文和响应报文
3、根据响应报文判断接口调用是否成功
4、输出最终测试结果:循环次数,成功次数,失败次数
请求报文样例:
{
"appId":"",
"stbId":"stbId_123456789",
"userId":"userId_123456789",
"ppvId":"ppvId_123456789",
"contentId":"contentId_123456789",
"transationId":"transationId_123456789",
"serviceType":"",
"recordTime":""
}
响应报文样例:
{
"result":"",
"resultNotes":"",
"transationId":"transationId_123456789"
}
测试脚本:vuser_init、Action、vuser_end、globals.h
vuser_init():
vuser_init()
{
return ;
}
Action():
Action()
{
// 定义请求报文的URL
char requestUrl[] = "URL=http://21.254.43.61:6663/eps/eps?command=freeTrialNotice"; // 定义请求报文的BODY,对参数stbId参数化
char requestBody[] = "BODY="
"\n{\n"
" \"appId\":\"10101\",\n"
" \"stbId\":\"{freeTrialNotice}\",\n"
" \"userId\":\"userId_123456789\",\n"
" \"ppvId\":\"ppvId_123456789\",\n"
" \"contentId\":\"contentId_123456789\",\n"
" \"transationId\":\"transationId_123456789\",\n"
" \"serviceType\":\"2\",\n"
" \"recordTime\":\"20150115105332\"\n"
"}\n"; // 从响应报文中获取参数result
web_reg_save_param("result",
"LB=\"result\":\"",
"RB=\",",
LAST); // 从响应报文中获取参数resultNotes
web_reg_save_param("resultNotes",
"LB=\"resultNotes\":\"",
"RB=\",",
LAST); // 从响应报文中获取参数transationId
web_reg_save_param("transationId",
"LB=\"transationId\":\"",
"RB=\"",
LAST); // 发起请求
web_custom_request("freeTrialNoticeTest",
"Method=POST",
"RecContentType=text/html",
requestUrl,
requestBody,
LAST); // 打印请求报文
lr_output_message("\n请求报文%s\n请求报文%s",requestUrl,requestBody); // 打印freeTrialNotice变量值
lr_output_message("freeTrialNotice=%s",lr_eval_string("{freeTrialNotice}")); // 打印响应报文
lr_output_message("响应报文:\n"
"{\n"
" \"result\":\"%s\",\n"
" \"resultNotes\":\"%s\",\n"
" \"transationId\":\"%s\"\n"
"}\n",
lr_eval_string("{result}"),
lr_eval_string("{resultNotes}"),
lr_eval_string("{transationId}")); // 根据返回的result判断接口调用是否成功,0:成功,非0:失败
if(atoi(lr_eval_string("{result}"))==){
lr_output_message("result为%s,接口调用成功",lr_eval_string("{result}"));
// 统计成功数
countSuccess += ;
}else{
lr_output_message("result为%s,接口调用失败",lr_eval_string("{result}"));
// 统计失败数
countFailed += ;
} return ;
}
vuser_end():
vuser_end()
{
// 打印最终的测试结果
lr_output_message("循环次数:%d,成功数:%d,失败数:%d",countSuccess + countFailed,countSuccess,countFailed);
return ;
}
globals.h:
#ifndef _GLOBALS_H
#define _GLOBALS_H //--------------------------------------------------------------------
// Include Files
#include "lrun.h"
#include "web_api.h"
#include "lrw_custom_body.h" // 定义全局变量 成功次数
int countSuccess = ; // 定义全局变量 失败次数
int countFailed = ; //--------------------------------------------------------------------
// Global Variables #endif // _GLOBALS_H
脚本循环执行3次,结果如下:
Virtual User Script started at : -- ::
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0. for Windows ; build (Aug ::) [MsgId: MMSG-]
Run Mode: HTML [MsgId: MMSG-]
Run-Time Settings file: "E:\VU\freeTrialNotice\\default.cfg" [MsgId: MMSG-]
Ending action vuser_init.
Running Vuser...
Starting iteration .
Starting action Action.
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): web_custom_request("freeTrialNoticeTest") was successful, body bytes, header bytes [MsgId: MMSG-]
Action.c():
请求报文URL=http://21.254.43.61:6663/eps/eps?command=freeTrialNotice
请求报文BODY=
{
"appId":"",
"stbId":"{freeTrialNotice}",
"userId":"userId_123456789",
"ppvId":"ppvId_123456789",
"contentId":"contentId_123456789",
"transationId":"transationId_123456789",
"serviceType":"",
"recordTime":""
}
Action.c(): freeTrialNotice=stbId_123456789
Action.c(): 响应报文:
{
"result":"",
"resultNotes":"",
"transationId":"transationId_123456789"
}
Action.c(): result为0,接口调用成功
Ending action Action.
Ending iteration .
Starting iteration .
Starting action Action.
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): web_custom_request("freeTrialNoticeTest") was successful, body bytes, header bytes [MsgId: MMSG-]
Action.c():
请求报文URL=http://21.254.43.61:6663/eps/eps?command=freeTrialNotice
请求报文BODY=
{
"appId":"",
"stbId":"{freeTrialNotice}",
"userId":"userId_123456789",
"ppvId":"ppvId_123456789",
"contentId":"contentId_123456789",
"transationId":"transationId_123456789",
"serviceType":"",
"recordTime":""
}
Action.c(): freeTrialNotice=stbId_12345678
Action.c(): 响应报文:
{
"result":"",
"resultNotes":"",
"transationId":"transationId_123456789"
}
Action.c(): result为0,接口调用成功
Ending action Action.
Ending iteration .
Starting iteration .
Starting action Action.
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): Registering web_reg_save_param was successful [MsgId: MMSG-]
Action.c(): web_custom_request("freeTrialNoticeTest") was successful, body bytes, header bytes [MsgId: MMSG-]
Action.c():
请求报文URL=http://21.254.43.61:6663/eps/eps?command=freeTrialNotice
请求报文BODY=
{
"appId":"",
"stbId":"{freeTrialNotice}",
"userId":"userId_123456789",
"ppvId":"ppvId_123456789",
"contentId":"contentId_123456789",
"transationId":"transationId_123456789",
"serviceType":"",
"recordTime":""
}
Action.c(): freeTrialNotice=
Action.c(): 响应报文:
{
"result":"",
"resultNotes":"蹇呭~鍙傛暟瀛樺湪绌哄€硷紒",
"transationId":"transationId_123456789"
}
Action.c(): result为1,接口调用失败
Ending action Action.
Ending iteration .
Ending Vuser...
Starting action vuser_end.
vuser_end.c(): 循环次数:,成功数:,失败数:
Ending action vuser_end.
Vuser Terminated.
loadRunner之接口测试的更多相关文章
- 基于LoadRunner构建接口测试框架
基于LoadRunner构建接口测试框架 http://www.docin.com/p-775544153.html
- 用LoadRunner实现接口测试
接口测试的两种方法 其实无论用那种测试方法,接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过 ...
- 使用Loadrunner进行接口测试
在工作中很多时候都需要进行接口测试,如果只是进行接口的功能测试这个很简单,两种类型: 1.如果是基于get的直接使用浏览器进行访问,查看服务器返回的数据是否正确就行, 2.如果是基于post的可以接触 ...
- Jmeter、Postman 、 loadrunner SoapUI 接口测试工具
一. loadrunner 简称 LR 二. Jmeter 1.安装包:apache-jmeter-4.0.tgz 解压.学会此工具的使用 和POSTman 一样的. 2.本机测试:双击apa ...
- LoadRunner Vuser接口测试脚本 Post举例
发送内容为JSON的POST请求需要加入"EncType=application/json",表单参数不需要.(JAVA API) // POST接口调用 web.custom_r ...
- Loadrunner 接口测试的两种方法
其实无论用那种测试方法,接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过程. 方法一.用Lo ...
- Jenkins+ANT+Jmeter 接口测试的实践(转载)
转载地址:https://testerhome.com/topics/5262 1.前言 最近感觉大家都在讲Jenkins+jmeter+ant或maven的使用,但没有说到具体怎么投入到项目使用,只 ...
- LR进行接口测试
其实无论用那种测试方法,接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过程. 方法一.用Lo ...
- web_custom_request函数做get接口测试
最近研究了使用loadrunner做接口测试,刚开始一直不成功,后来加了QQ群,遇到大神了,经指导终于成功 下面是具体实例代码: //{"signIOS":1,"sign ...
随机推荐
- Delphi 安装Cnpack cnvcl后界面不断弹出 Memory Manager's list capablity overflow ,please enlarge it!
Delphi 安装Cnpack cnvcl后界面不断弹出 Memory Manager's list capablity overflow ,please enlarge it! 解决方法:删除指定 ...
- C++ 穷举算法 鸡兔同笼
#include "stdio.h" int qiongju(int head, int foot, int *chicken, int *rabbit) { int re, i, ...
- 1,MySQL常用函数
一,MySQL聚合函数 1,AVG()函数 AVG()函数是一个聚合函数,它用于计算一组值或表达式的平均值. AVG()函数的语法如下: AVG(DISTINCT expression) 例如有如下p ...
- 【C++11新特性】 C++11智能指针之weak_ptr
如题,我们今天要讲的是C++11引入的三种智能指针中的最后一个:weak_ptr.在学习weak_ptr之前最好对shared_ptr有所了解.如果你还不知道shared_ptr是何物,可以看看我的另 ...
- php trim()函数 语法
php trim()函数 语法 trim()函数怎么用? php trim()函数用来删除字符串两端的空格或其他预定义字符,语法是trim(string,charlist),返回经过charlist处 ...
- 从头开始开发一个vue幻灯片组件
首先新建项目vue init webpack projectName 安装依赖包npm i这些就不说了 接下来就是构建我们的swiper组件 因为我写的代码不规范, 通不过eslint的检测, 会频繁 ...
- LVS负载均衡中arp_ignore和arp_annonuce参数配置
先简单的介绍下关于LVS负载均衡 LVS(Linux Virtual Server)Linux服务器集群系统 针对高可伸缩,高可用服务的需求,给予IP层和内容请求分发的负载均衡调度解决方法,并在Li ...
- [CSP-S模拟测试]:x(数学+并查集)
题目背景 $\frac{1}{4}$遇到了一道水题,叒完全不会做,于是去请教小$D$.小$D$都没看就切掉了这题,嘲讽了$\frac{1}{4}$一番就离开了.于是,$\frac{1}{4}$只好来问 ...
- yii2和laravel比较
yii2和laravel比较 一.总结 一句话总结: 开发速度两者相当:laravel的artisan工具和yii的gii有异曲同工的效果,借助于artisan工具,可以快速创建控制器.模型和路由等. ...
- Java执行static顺序
1.定义: 1. Java中静态变量只能在类主体中定义,不能在方法中定义. 静态变量属于类所有而不属于方法. 2. 静态块:用static申明,JVM加载类时执行,仅执行一次 构造块:类中 ...