其实可以用jmeter两种sampler进行webservice的测试:
1、SOAP/XML-RPC Request(但是在jmeter3.2以后版本中已经取消了这个取样器)
2、HTTP请求
下面分别介绍两种方式
一、首先需要使用soupUI工具抓取webservice接口的部分需要的信息。
1、新建项目

2、新建成功的项目信息如下图:

3、选择要测试的接口,右键新建request

4、编辑报文内容,点击左上角的绿色三角执行按钮,右侧窗口查看接口请求结果

5、可以复制下发送的报文的格式
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
<soap:Header/>
<soap:Body>
<web:getSupportCity>
<!--Optional:-->
<web:byProvinceName>?</web:byProvinceName>
</web:getSupportCity>
</soap:Body>
</soap:Envelope>
二、使用SOAP/XML-RPC Request(但是在jmeter3.2以后版本中已经取消了这个取样器)形式进行测试,以下随便放一张图,因为我用的jmeter版本是3.3,么有SOAP/XML-RPC Request sampler,而是主要用的第二种测试形式。

|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 | <soapenv:Envelope xmlns:soapenv=``"http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web=``"http://WebXml.com.cn/"``>
``<soapenv:Header/>
``<soapenv:Body>
``<web:getTVstationString>
``<web:theAreaID>``12``</web:theAreaID>
``</web:getTVstationString>
``</soapenv:Body>
</soapenv:Envelope>
|
soapaction的地址:为第1行数据和第4行接口的相叠加的内容
1 web="http://WebXml.com.cn/"
4 <web:getTVstationString>
形成地址:http://WebXml.com.cn/getTVstationString
对于公共的webservice接口,可以使用soapUI进行抓取,或者是其他工具去抓取发送报文的格式
三、使用HTTP请求sampler来测试webservice接口
1、建立HTTP请求,如图,请求内容写在BODY DATA里,选择方法为post

python
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getSupportCity xmlns="http://WebXml.com.cn/">
<byProvinceName>河南</byProvinceName>
</getSupportCity>
</soap:Body>
</soap:Envelope>
2、建立HTTP头信息,如下
Soapaction地址和第一种方法一致

3、接着建立下一个接口请求,方式同上

python
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getWeatherbyCityName xmlns="http://WebXml.com.cn/">
<theCityName>${b1}</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>

4、最终执行的请求结果如下图:




总结:
感谢每一个认真阅读我文章的人!!!
我个人整理了我这几年软件测试生涯整理的一些技术资料,包含:电子书,简历模块,各种工作模板,面试宝典,自学项目等。欢迎大家点击下方名片免费领取,千万不要错过哦。
