.png)
4)点击OK按钮等到的脚本如下
soap_request("StepName=SOAP Request", //步骤名称
"SOAPEnvelope=" //发送到服务器的XML
"<soap:Body>"
"<theCityName>南京</theCityName>"
"</getWeatherbyCityName>"
"</soap:Body>"
"</soap:Envelope>",
"ResponseParam=response", //存储服务器响应返回参数
"Snapshot=t1555556002.inf",
LAST);
5)加入事务,参数化与if,对脚本进行判断(注意输入参数为中文时,需要将NULL编码转换为utf-8,输出内容为乱码是需要将utf-8编码转换为NULL,使用lr_convert_string_encoding函数)
lr_convert_string_encoding(lr_eval_string("{cityname}"),NULL,"utf-8","city");
lr_save_string(lr_eval_string("{city}"),"city_name");
//添加事务
lr_start_transaction("getcityname");
soap_request("StepName=SOAP Request", //步骤名称
"SOAPEnvelope=" //发送到服务器的XML
"<soap:Body>"
"<theCityName>{city_name}</theCityName>"
"</getWeatherbyCityName>"
"</soap:Body>"
"</soap:Envelope>",
"ResponseParam=response", //存储服务器响应返回参数
"Snapshot=t1555556002.inf",
LAST);
//返回的信息乱码转译,并高亮打印
lr_convert_string_encoding(lr_eval_string("{response}"),"utf-8",NULL,"msg");
lr_error_message(lr_eval_string("{msg}"));
//返回值为xml文件格式,该函数自动将返回值转变为中文的了,不需要使用lr_convert_string_encoding,本例获取城市信息
lr_xml_get_values(
"XML={response}",//查看的xml
"Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]", //查看返回内容路径在,指定元素或者属性
"ValueParam=getcityname", //存储返回的值
LAST);
//本例获取城市天气信息,与脚本判断无关,实际脚本中可以不需要,这边是强化记忆来着
lr_xml_get_values(
"XML={response}",//查看的xml
"Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[11]", //查看返回内容路径在,指定元素或者属性
"ValueParam=getWeatherby", //存储返回的值
LAST);
//断言判断
if(strcmp(lr_eval_string("{getcityname}"),lr_eval_string("{cityname}"))==0)
{
lr_end_transaction("getcityname", LR_PASS);
lr_output_message("成功查询出%s的今日天气情况:%s",lr_eval_string("{cityname}"),lr_eval_string("{getWeatherby}"));
}
else
{
lr_end_transaction("getcityname", LR_FAIL);
lr_output_message("查询失败,输入的城市与返回的城市信息不一致,输入城市信息为%s,返回城市信息为%s",lr_eval_string("{cityname}"),lr_eval_string("{getcityname}"));
}
6)脚本执行结果如下(实测无问题)
.png)
3.可以使用web_custom_request()函数,也可以做web service协议:
1)将鼠标放置到需要插入脚本的地方,右击,选择增加步骤,输入 web_custom_request,弹出对应设置框
.png)
2)点击OK得到的脚本如下
web_custom_request("web_custom_request",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"EncType=text/xml; charset=utf-8",
"Body=<?xml version="1.0" encoding="utf-8"?>
<soap:Body>
<theCityName>string</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>",
LAST);
3)需要将body中的“”进行转译,且Body都需要加上引号,优化之后如下
web_custom_request("web_custom_request",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"EncType=text/xml; charset=utf-8",
"Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>"
" <soap12:Body>"
"<theCityName>string</theCityName>"
"</getWeatherbyCityName>"
"</soap12:Body>"
"</soap12:Envelope>",
LAST);
4)加入事务,加关联,if,对脚本进行判断(注意使用lr_convert_string_encoding函数转码)
lr_convert_string_encoding(lr_eval_string("{cityname}"),NULL,"utf-8","city");
lr_save_string(lr_eval_string("{city}"),"city_name");
web_reg_save_param_ex(
"ParamName=weather_city",
"LB=<string>",
"RB=</string>",
"Ordinal=2",
SEARCH_FILTERS,
LAST);
lr_convert_string_encoding(lr_eval_string("{weather_city}"),NULL,"utf-8","weather_city1");
lr_error_message(lr_eval_string("{weather_city1}"));
lr_start_transaction("weather");
web_custom_request("web_custom_request",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"EncType=text/xml; charset=utf-8",
"Body=<?xml version=\"1.0\" encoding=\"utf-8\"?>"
" <soap12:Body>"
"<theCityName>{city_name}</theCityName>"
"</getWeatherbyCityName>"
"</soap12:Body>"
"</soap12:Envelope>",
LAST);
if(strcmp(lr_eval_string("{weather_city1}"),lr_eval_string("{cityname}"))==0)
{
lr_end_transaction("weather", LR_PASS);
}
else
{
lr_end_transaction("weather", LR_FAIL);
}
SOAP工具的简单实用
当我们只知道wsdl地址时,我们可以使用该工具知道具体的请求体,具体如下
1)打开工具,点击页面上的SOAP
2)点击ok,成功项目,点击其他具体的接口,可查看到请求体信息,输入参数,即可得到返回信息(左边请求信息,右边返回信息)
.png)

- 性能测试总结工作总结-基于WebService协议脚本 内置函数手动编写
LoadRunner基于WebService协议脚本 WebService协议脚本有三种生成方式,一种是直接通过LoadRunner导入URL自动解析生成:一种是使用LoadRunner内置函数手动编 ...
- LR11中webservice协议的性能测试应用
使用LR11对webservice协议的接口测试应用 脚本开发步骤:1.打开vuser generator,新建一个脚本,选择webservice协议:2.选择Manage Services(服务管理 ...
- LR编写webservice协议接口
转自:http://lovesoo.org/use-loadrunner-call-webservice-interface-testing-optimization-summary.html 本文主 ...
- webservice中采用协议Http,它是指什么意思
webservice 协议 Web Service使用的是 SOAP (Simple Object Access Protocol)协议soap协议只是用来封装消息用的.封装后的消息你可以通过各种已有 ...
- LoadRunner系列之—-02 基于webservice协议的接口测试(脚本实例)
Loadrunner 基于webservice协议的接口压力测试(脚本实例) 接口功能如下:请求接口,报文只有一个参数为证件号码:返回报文中,有证件号码是否能查到对应数据,查到几条数据. 思路:请求w ...
- Loadrunner测试webservice协议总结
Loadrunner测试webservice协议总结 一.协议选择 1.打开Virtual user generator,新建脚本,选择webservice协议
- Loadrunner11点击录制脚本无响应,IE页面弹不出——解决方案汇总
以前用Loadrunner的时候都没有遇到过这个问题,后来将服务器重装系统(win7)后,重新安装Loadrunner11,浏览器版本刚开始为IE11,后来降为IE8,IE访问部署在虚拟机里的平台能正 ...
- lr_java user协议脚本开发
1.准备工作,安装jdk,配置环境变量 lr11 jdk1.6 32位 lr12 jdk1.7 32位 注:若原已安装了jdk1.8,现要安装jdk1.7,若遇到安装好1.7并配置好环境后,在cmd中 ...
- [WebService].net中WebService的使用实例
.net中WebService的使用实例 一.创建一个Webwebservice 1.新建一个项目WebserverDemo 2.在项目处添加新建项,添加一个web服务 3.编辑TestServer. ...
随机推荐
- Sketchup (待续)
Sketchup插件 来自20个最好用的SketchUp插件 https://www.bilibili.com/video/av17242031/?from=search&seid=15336 ...
- Python 上下文管理协议中的__enter__和__exit__基本理解
所谓上下文管理协议,就是咱们打开文件时常用的一种方法:with __enter__(self):当with开始运行的时候触发此方法的运行 __exit__(self, exc_type, exc_va ...
- C#通过Ado.net对连接数据库并进行添加删除等常规操作的代码
如下资料是关于C#通过Ado.net对连接数据库并进行添加删除等常规操作的内容. static string sqlcon = "server=.;database=;Integrated ...
- redis 在 php 中的应用(Hash篇)
本文为我阅读了 redis参考手册 之后结合 博友的博客 编写,注意 php_redis 和 redis-cli 的区别(主要是返回值类型和参数用法) Redis hash 是一个string类型的f ...
- 2019 Lonsdor K518S VS K518ISE
2019 Lonsdor K518S VS K518ISE: The same: IMMO capabilities + Vehicle coverage. The difference: The u ...
- 画多边形form并填充背景色(可以实现圆角边框 有锯齿)
public Form1() { InitializeComponent(); this.BackColor = ColorTranslator.FromHtml("#F7F1F1" ...
- oracle 表空间管理相关(原创)
通过以下几步基本可以查看表空间情况以及处理表空间不足问题. ASM相关 查看asm空间 select group_number,name,total_mb,free_mb from v$asm_dis ...
- android开发_ViewGroup(组视图)-- 五大布局
view组--ViewGroup(组视图) ViewGroup的作用:在view中添加子控件.ViewGroup的5个子类,就是五大布局: (1) LinearLayout 线性布局(常用) (2) ...
- 那些按烂的Linux命令集合贴
#查看80端口运行情况netstat -anp|grep 80 #关闭某个进程(如8848pid) kill -9 8848 #运行java的war包 java -jar myproj.war #持续 ...
- company_credit
/** * Created by wu-yj on 2016/5/6. */ import java.sql.{Connection, DriverManager, PreparedStatement ...