大略的说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">186217986</NameID> </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">1862179863</NameID> </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文档的描述不断的丰富测试场景。希望对你有所帮助。