WebService是什么?
简单的说WebService是一个SOAP(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言(通过 xml 描述)间的相互调用,通过Internet进行基于Http协议的网络应用间的交互。通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。(概念性的东西大家可以自行搜索补充)
测试环境准备
python2.7 + httplib 内置库
数据准备
这里就定义了两个case:
case1是一个正向case, 根据正确的nameid查询用户信息。 case2是一个反向case, 给出一个错误的nameid 查询用户信息。
然后将这两个case 存放到一个dict 中,最后引入代码里面进行请求使用。
data.py文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#正向的case
case1
=
'''<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<OGHeader xmlns="http://webservices.micros.com/og/4.3/Core/" transactionID="2019062118114433750450">
<Origin entityID="OW1" systemType="WEB"/>
<Destination entityID="TI" systemType="ORS"/>
</OGHeader>
</soap:Header>
<soap:Body>
<FetchProfileRequest xmlns="http://webservices.micros.com/oqq/5.1/Name.wsdl">
<NameID type="INTERNAL">186217986</NameID>
</FetchProfileRequest>
</soap:Body>
</soap:Envelope>'''
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#反向的case
case2
=
'''<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<OGHeader xmlns="http://webservices.micros.com/og/4.3/Core/" transactionID="2019062118114433750450">
<Origin entityID="OW1" systemType="WEB"/>
<Destination entityID="TI" systemType="ORS"/>
</OGHeader>
</soap:Header>
<soap:Body>
<FetchProfileRequest xmlns="http://webservices.micros.com/oqq/5.1/Name.wsdl">
<NameID type="INTERNAL">1862179863</NameID>
</FetchProfileRequest>
</soap:Body>
</soap:Envelope>'''
dict1
=
{
"success"
:case1,
"fail"
:case2}
test.py文件内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#coding=utf-8
import
httplib
from
data
import
dict1
def
Featchinfo():
url
=
"test.beat.com"
port
=
9700
path
=
"/oqq_ws_51/Name.asmx"
header
=
{
'Content-Type'
:
'text/xml; charset=utf-8'
}
conn
=
httplib.HTTPConnection(url,port,timeout
=
10
)
for
key,value
in
dict1.items():
conn.request(
'POST'
,path,value.encode(
'utf-8'
),header)
response
=
conn.getresponse()
resp
=
response.read()
if
(key
=
=
"success"
and
"resultStatusFlag=\"SUCCESS"
in
str
(resp)):
print
(
"case1 验证通过"
)
elif
(key
=
=
"fail"
and
"resultStatusFlag=\"FAIL"
in
str
(resp)):
# print(resp)
print
(
"case2 验证通过"
)
if
__name__
=
=
'__main__'
:
Featchinfo()
结果输出: case2 验证通过 case1 验证通过
总结
通过以上简单的几步就可以完成WebService Api的测试,对于示例中的测试数据大家可以根据Api文档的描述不断的丰富测试场景。
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走! 希望能帮助到你!【100%无套路免费领取】