WebService自动化-WSDL调用
来源:才华咖 本文已影响1.68W人
来源:才华咖 本文已影响1.68W人
在做自动化测试的过程中,有时候需要测试一个业务流程特定的部分, 这个特定部分可能是接口,它往往需要依赖前期产生的数据输出作为输入,这个时候,重新跑一遍前边流程来获得需要的数据显然不合理, 那么利用后端开发发布出来的web service来直接生成所需数据就显得尤为便捷, 今天我们就来看如何利用suds调用web service。
Suds is a lightweight SOAP python client for consuming Web Services.
The suds Client class provides a consolidated API for consuming web services. The object contains (2) sub-namespaces:
service
The service namespace provides a proxy for the consumed service. This object is used to invoke operations (methods) provided by the service endpoint.
factory
The factory namespace provides a factory that may be used to create instances of objects and types defined in the WSDL.
suds Client 是作为一个API来消费提供的web services, 它有两个子命名空间:
Service :对象用来调用被消费的web service提供的方法。
Factory:提供一个工厂用来生成一个定义在WSDL的对象或方法的实例。
简单来说就是service用来直接调用web service里的方法,factory用来生成一个web service对象实例。
我们用一段代码来说明:
from nt import Client
class WebServices(object):
WSDL_ADDRESS = "http://*/services/*/
def __init__(self):
_service = Client(_ADDRESS)
print _service
def is_class_booked(self, class_id, member_id):
return _assBooked(class_id, member_id)["ClassBooked"]
def cancel_clas(self, class_id, member_id):
parameter = _te("CancelClass")
print parameter
print dir(parameter)
s_id = class_id
er_id = member_id
elBy = 'T'
elReason = 'test'
return _elClass(m)
if __name__ == '__main__':
web_service_class = WebServices()
print web_service__class_booked('315983', '23540202')
print web_service_el_clas('315983', '23540202')
以上代码里:
WSDL_ADRESS:是我们提供的web service的地址。
__init__方法: 实现了suds client的生成, client的用法如下:
from nt import Client
url = 'http://*.?wsdl'
client = Client(url)
is_class_booked 方法:使用了client的service这个命名空间,即直接调用web service 的可用方法。那么如何知道哪个方法如何调用呢?
参考代码里__init__方法的print语句,打印出来了所有可用的方法和类型, print的打印结果片段如下:
Suds ( ) version: 0.4 GA build: R699-20100913
Service ( StudentPrivateLessonService ) tns=""
Prefixes (9)
ns0 = "iceParams"
ns1 = "entPrivateLesson"
*
ns8 = ""
Ports (1):
(BasicHttpBinding_IStudentPrivateLessonService)
Methods (18):
*
CancelClass(ns1:CancelParameter param, )
*
IsClassBooked(xs:int class_id, xs:int member_id, )
*
Types (47):
ns4:ArrayOfBatchCancelDetail
ns4:ArrayOfBookablePLClass
ns4:ArrayOfBookedPLClass
*
从打印结果可以看出,IsClassBooked方法可以直接调用,它需要2个参数,类型为int型。
Cancel_class方法:利用了 client的factory这个命名空间。
parameter = _te("CancelClass")
创建了Cancel Class这个方法的一个实例,然后通过 print parameter,可以看出这个函数的参数组成:
suds_inpect.png
它是一个字典,字典的m的值又是一个字典,故我们要调用这个方法时下需要用s_id 这样的方式来引用。
下图是整段代码的运行结果:
证明成功,我们再去DB里查下结果:
可以看出,有一条心的记录添加出来。
以上,只要给出WSDL的地址,导入suds,通过Client, service, factory这3个类就可以实现web services的自动化调用,是不是很简单?
Windows系统里的SQLServer辅导资料
《The Prevalence of Western Holidays》英语四级作文
英语阅读:Covergirl unveils empowering brand update
JavaScript在Android的WebView中parseInt函数转换不正确
大学英语演讲稿:Television News Coverage
英语作文Some advice on how to learn English well
Axis2创建WebService实例教程
学习Dreamweaver的CSS网页布局ul和li
WebServices简介
六级英语写作范文:The Celebration of Western Festivals
WebSphere MQ Solution Designer认证考试
Java如何调用WebService
PHP中使用XML-RPC构造Web Service简单入门
Diaspora Finance Powers Global Development美文欣赏
Windows系统服务器技术SQLServer辅导资料
Windows Server操作系统详细安装教程
英语作文: The Uncivilized Internet Words
英语作文:大学生村官 College Graduates Work as Village Offic
A Lifeguard at Johns Beach Saved a Drowning Child,A Lifeguar英语作文
高中生优秀英语作文:Have a break away from electronics
GRE数学考点《Distributive Law》举例分析
关于Adobe Dreamweaver CS5的考试大纲
托福词汇之“运动寡妇Exercise widow”
如何创建安全的Web Service
The Emperor of Heaven Bestows Wine天帝赐酒(双语)
Adobe Dreamweaver CS6考试大纲
Adobe Dreamweaver CS3考试大纲
英语阅读:Life is inevitable consequence of physics
Efforts Urged to Improve Womens Reproductive Health英语阅读
Camera Club needs new members英语作文
WindowsHomeServer常见问题解答汇总
WindowsHomeServer常见问题
如何压缩Web Service数据
Adobe Dreamweaver CS4考试大纲
Scientists Build Robots to Live With Humans英语美文
WebService的优缺点