http和webservice接口测试有什么区别?

webservice的基础组成是http+xml

三要素:soap传输协议,uddi,wsdl(webservice描述语言xml格式)

优点:跨平台,跨程序

缺点:xml格式,传输和解析耗费资源大

一。wsdl接口怎样使用python测试

官网文档地址:https://fedorahosted.org/suds/wiki/Documentation

1.什么是wsdl接口,本质是xml,框架很多比如cxf

2.python怎样调用wsdl接口,suds模块

入门例子,了解下wsdl和suds的样子

查询ip归属地

>>> import suds
>>> url="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl"
>>> client=suds.client.Client(url)
>>> print client

打印结果:描述的很清楚,包括seivice,port 和method,直接调用你需要的

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( IpAddressSearchWebService ) tns="http://WebXml.com.cn/"
Prefixes (1)
ns0 = "http://WebXml.com.cn/"
Ports (2):
(IpAddressSearchWebServiceSoap)
Methods (3):
getCountryCityByIp(xs:string theIpAddress, )
getGeoIPContext()
getVersionTime()
Types (1):
ArrayOfString
(IpAddressSearchWebServiceSoap12)
Methods (3):
getCountryCityByIp(xs:string theIpAddress, )
getGeoIPContext()
getVersionTime()
Types (1):
ArrayOfString

调用方法:

res=client.service['IpAddressSearchWebServiceSoap12'].getCountryCityByIp('8.8.8.8')
print res

返回结果:

(ArrayOfString){
string[] =
"8.8.8.8",
"美国 加利福尼亚州山景市谷歌公司DNS服务器",
}

2.如果wsdl比较复杂,比如有多个service和port,使用client.service[service][port].getBank(),

如果不指定,默认是第一service的第一个port的第一个method

下面的就可以写成这样
client.service['OtherBLZService']['soap'].getBank()
client.service[1][0].getBank()
Suds - version: 0.3.7 build: (beta) R550-20090820

Service (BLZService) tns="http://thomas-bayer.com/blz/"
Prefixes (1)
ns0 = "http://thomas-bayer.com/blz/"
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType Service (OtherBLZService) tns="http://thomas-bayer.com/blz/"
Prefixes (1)
ns0 = "http://thomas-bayer.com/blz/"
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType

复杂参数:

Suds - version: 0.3.3 build: (beta) R397-20081121

Service (WebServiceTestBeanService) tns="http://test.server.enterprise.rhq.org/"
Prefixes (1):
ns0 = "http://test.server.enterprise.rhq.org/"
Ports (1):
(Soap)
Methods:
addPerson(Person person, )
echo(xs:string arg0, )
getList(xs:string str, xs:int length, )
getPercentBodyFat(xs:string name, xs:int height, xs:int weight)
getPersonByName(Name name, )
hello()
testExceptions()
testListArg(xs:string[] list, )
testVoid()
updatePerson(AnotherPerson person, name name, )
Types (23):
Person
Name
Phone
AnotherPerson

首先看下type里参数是什么样子的

c=suds.client.Client(url)
person=c.factory.create('Person')
print person
(Person)=
{
phone = []
age = NONE
name(Name) =
{
last = NONE
first = NONE
}
}

赋值有2中方法

1.基本:

phone = client.factory.create('Phone')
phone.npa = 202
phone.nxx = 555
phone.number = 1212
name = client.factory.create('Name')
name.first = 'Elmer'
name.last = 'Fudd'
person.name = name
person.age = 35
person.phone = [phone] json person{}
phone={'npa':202,'nxx':222,'number':'2222',}
name={'first':'li','last':'mi'} person['name']=name
person['age']=22
person['phone']=[phone,]

使用jmeter测试webservice接口,可查看我后来写的

https://www.cnblogs.com/xueli/p/9681526.html

二。http接口

使用requests

1.无参数get

 r = requests.get('http://httpbin.org/get')
print r.text {
"args": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, compress",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.2.1 CPython/2.7.5 Windows/7"
},
"origin": "223.202.116.5",
"url": "http://httpbin.org/get"
}

有参数get

r = requests.get('http://www.so.com/s',params = {'q':'wwwww'})
print r.text

2.post,参数是字典

payload = {'name':'mmmmmmiiiiii','con':'hello'}
r = requests.post("http://httpbin.org/post", data=payload)
print r.text {
"args": {},
"data": "",
"files": {},
"form": {
"con": "hello",
"name": "mmmmmmiiiiii"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, compress",
"Content-Length": "",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.2.1 CPython/2.7.5 Windows/7"
},
"json": null,
"origin": "223.202.116.5",
"url": "http://httpbin.org/post"
}

post,参数是json

>>> payload = {'name':'tttttlililililili','con':'hello'}

>>> import json

>>> r = requests.post('http://httpbin.org/post', data=json.dumps(payload))

定制headers,使用headers参数来传递

 headers = {'content-type': 'application/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)

python接口测试wsdl的更多相关文章

  1. Python接口测试实战5(下) - RESTful、Web Service及Mock Server

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  2. Python接口测试实战1(上)- 接口测试理论

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  3. Python接口测试实战4(下) - 框架完善:用例基类,用例标签,重新运行上次失败用例

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  4. Python接口测试实战5(上) - Git及Jenkins持续集成

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  5. Python接口测试实战4(上) - 接口测试框架实战

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  6. Python接口测试实战3(下)- unittest测试框架

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  7. Python接口测试实战3(上)- Python操作数据库

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  8. Python接口测试实战2 - 使用Python发送请求

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  9. Python接口测试实战1(下)- 接口测试工具的使用

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

随机推荐

  1. node开发指南

    Node.js 能做什么 正如 JavaScript 为客户端而生,Node.js 为网络而生.Node.js 能做的远不止开发一个网站那么简单,使用 Node.js,你可以轻松地开发: 具有复杂逻辑 ...

  2. CAST()函数

    语法: CAST(expression AS data_type) 参数说明: expression:任何有效的SQServer表达式 AS:用于分割两个参数,在AS之前的是需要处理的数据,在AS之后 ...

  3. 使用Runtime.getRuntime().exec()在java中调用python脚本

    举例有一个Python脚本叫test.py,现在想要在Java里调用这个脚本.假定这个test.py里面使用了拓展的包,使得pythoninterpreter之类内嵌的编译器无法使用,那么只能采用ja ...

  4. 转载《遭受arp攻击怎么办》

    ARP(Address Resolution Protocol,地址解析协议)协议的基本功能就是通过目标设备的IP地址,查询目标设备的MAC地址,以保证通信的进行.ARP攻击仅能在以太网(局 域网如: ...

  5. C#实现Excel的导入导出

    Excel作为日常使用工具,在开发过程中经常会用到其导入导出功能.经过一个小的练习,学习了下导入导出功能. 导出篇: 从数据库查询到所要导出的数据,以xml的形势保存下来,最后输出excel的格式,保 ...

  6. 涵涵和爸爸习惯养成进度表(三)(June 25 - )

    规则说明 23天内,没有哭脸,不超过三个无表情脸,可以给一个奖励(动画书等) 涵涵违反规则,在爸爸和妈妈都同意的情况下,可以给无表情脸 爸爸违反规则,在妈妈和涵涵都同意的情况下,可以给无表情脸 获奖记 ...

  7. DTD指定了游戏规则。

    1.DTD的作用 DTD是XML的型,列出了XML中的元素有哪些.元素间的关系.元素可以有哪些内容,元素的属性也有哪些.DTD实质说明的是元素间的关系,也就是类之间的关系.是一棵树状结构的说明,与XM ...

  8. freeswitch:error C2220: 警告被视为错误 - 没有生成“object”文件

    项目 -> 属性-> 配置属性 -> c/c++ -> 将警告视为错误 -> 否 参考: http://www.cnblogs.com/kex1n/archive/201 ...

  9. .net core学习笔记(3)-依赖注入

    .net core 中使用了大量的依赖注入,对依赖注入一直是一知半解,总想不透,项目中用的是一个网上的开源框架,从底层到web层都是用的构造函数依赖注入. 然后了在继承ActionFilterAttr ...

  10. Cardinal样条曲线的Javascript实现(代码篇)

    由上一篇文章得到了Cardinal曲线的矩阵表达式,下面就这个矩阵表达式就可以来对曲线进行插值了. 这里选用了JS来实现,完全是因为之前交作业的时候还不知道怎么在Xcode里建完整的C++OpenGL ...