WebService是什么
简单的说WebService是一个SOAP(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言(通过 xml 描述)间的相互调用,通过Internet进行基于Http协议的网络应用间的交互。通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。(概念性的东西大家可以自行搜索补充)
测试环境准备
python2.7 + httplib 内置库
数据准备这里就定义了两个case:
case1是一个正向case, 根据正确的nameid查询用户信息。
case2是一个反向case, 给出一个错误的nameid 查询用户信息。
然后将这两个case 存放到一个dict 中,最后引入代码里面进行请求使用。
data.py文件内容如下:
#正向的casecase1='''<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">186217986NameID> FetchProfileRequest> soap:Body> soap:Envelope>'''
#反向的casecase2='''<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">1862179863NameID> FetchProfileRequest> soap:Body> soap:Envelope>'''dict1={"success":case1,"fail":case2}
test.py文件内容如下:
#coding=utf-8import httplibfrom data import dict1def 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文档的描述不断的丰富测试场景。与君共勉,每天进步一点点。
友情提示:“无量测试之道”原创著作,欢迎关注交流,禁止第三方不显示文章来源时转载。更多原创文章请扫码关注查看,交流与合作请联系:loadkernel@126.com。
QQ技术交流群:41564936
Python 实现Excel自动化办公《上》
Python 实现Excel自动化办公《中》
Python 实现Excel自动化办公《下》
Python API自动化测试实操
Python 测试框架之 Unittest & Pytest
Python 爬虫之Scrapy《下》
Python 爬虫之Scrapy《中》
Python 一招搞定禅道提交bug
Shell 编程核心技术《四》
Shell 编程核心技术《三》
Git 必知必会《上》
Git 必知必会《下》