【发布时间】:2018-12-05 13:13:50
【问题描述】:
我正在尝试使用 RobotFramework 测试soap 1.2 服务。到目前为止,我们只测试了使用RobotFramework suds 库的soap 1.1 服务,suds 与soap 1.2 不兼容。
向后兼容是新服务的一个选项,但最好有一个更长期的解决方案。我不是经验丰富的程序员,但如果告诉我要编辑什么和在哪里,我可以编辑代码。
在我们对使用 suds 的 soap 1.2 服务进行的测试中发生的情况是:suds 无法解释它从 web 服务获得的响应并给出以下错误:SAXParseException: :159:229: mismatched tag
soap消息很好,在SoapUI中使用没有问题。
我在网上找到了一些 sn-ps,建议我可以让 suds 库与 soap 1.2 一起用于我的 RobotFramework 测试。但我几乎没有编程经验,也不知道如何将这些 sn-ps 合并到 suds 中。 有人在这个 sn-p 上评论说,这解决了他与 RobotFramework 和 suds 的问题。
有没有人愿意解释我如何才能做到这一点?我自己似乎无法弄清楚。任何建议将不胜感激。
from suds.client import Client
from suds.bindings import binding
import logging
USERNAME = 'username'
PASSWORD = 'password'
# Just for debugging purposes.
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Telnic's SOAP server expects a SOAP 1.2 envelope, not a SOAP 1.1 envelope
# and will complain if this hack isn't done.
binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
client = Client('client.wsdl',
username=USERNAME,
password=PASSWORD,
headers={'Content-Type': 'application/soap+xml'})
# This will now work just fine.
client.service.someRandomMethod()
【问题讨论】:
-
你使用的是哪个 Python 版本?
-
验证 1.1 和 1.2 之间的关键区别是
Content-Type的 HTTP 标头值已更改为'application/soap+xml'。这应该是你调查的重点。我对 SudsLibrary 的体验并不好,所以我建议尝试分叉或评估自定义实现。 -
感谢您的回复。我们是 2.7。升级不是现在的选择。到目前为止,出于测试目的,Suds 运行良好(robotframework-sudslibrary)。我曾尝试专注于将 HTTP 标头更改为 application/soap+xml,但到目前为止,我还没有弄清楚如何以一种可行的方式做到这一点。自定义实现实际上是我试图通过集成命名 sn-p 来做的事情。我只是不知道怎么做。
标签: soap robotframework webservice-client suds