首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用suds库在RobotFramework中测试SOAP1.2服务

使用suds库在RobotFramework中测试SOAP1.2服务
EN

Stack Overflow用户
提问于 2018-12-05 21:13:51
回答 1查看 1.7K关注 0票数 2

我正在尝试使用RobotFramework测试SOAP1.2服务。到目前为止,我们只使用RobotFramework的suds库测试了SOAP1.1服务,并且suds与SOAP1.2不兼容。

向后兼容是新服务的一个选项,但最好是有一个更长期的解决方案。我不是一个有经验的程序员,虽然我可以编辑代码,如果被告知要编辑什么和在哪里。

在我们对使用suds的SOAP1.2服务的测试中发生的情况是: suds无法解释它从webservice获得的响应,并给出这个错误: SAXParseException::159:229: mismatched tag

soap消息很好,在SoapUI中使用它是没有问题的。

我在网上找到了一些片段,它们建议我可以让suds库在我的RobotFramework测试中使用SOAP1.2。但我几乎没有编程经验,也不知道如何将这些代码片段合并到suds中。有人在这段代码上评论说,这解决了他使用RobotFramework和suds的问题。

有没有人愿意解释一下我是如何工作的?我自己好像想不出来。任何建议都将不胜感激。

代码语言:javascript
复制
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()

代码片段来自:https://gist.github.com/kgaughan/858851

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-13 04:09:17

简而言之,Suds不支持SOAP 1.2绑定。开发已经停止了很长一段时间。由于这个原因,SudsLibrary也不支持它。

我使用example service SOAP 1.1/1.2观察到的一些差异是:

  1. header Content-Type
    • 1.2 = "application/soap+xml"
    • 1.1 = "text/xml".

  1. header
    • 1.2 = Action
    • 1.1 = SOAPAction

  1. Envelope Namespace
    • 1.2 = "http://www.w3.org/2003/05/soap-envelope"
    • 1.1 = "http://schemas.xmlsoap.org/soap/envelope/"

对于其中的每一个,在下面的示例中都实现了一个单独的解决方案。内容类型可能会被覆盖。可以添加操作,但不能删除SOAPAction。也可以使用扩展库覆盖命名空间。如果您的服务忽略SOAPaction标头属性,这应该适用于您。

测试Case.robot

代码语言:javascript
复制
*** Settings ***
Library    SudsLibrary
Library    SudsLibraryExtension
Library    Collections    

*** Test Cases ***
TC
    ${BASE_URL}    Set Variable         http://www.holidaywebservice.com
    ${SERVICE}     Create Dictionary    
    ...                                 name=HolidayService_v2    
    ...                                 wsdl=HolidayService2.asmx?WSDL
    ${PORT}        Set variable         HolidayService2Soap12
    ${METHOD}      Set variable         GetCountriesAvailable

    Set Binding     SOAP-ENV    http://www.w3.org/2003/05/soap-envelope
    Create Soap Client     ${BASE_URL}/${SERVICE.name}/${SERVICE.wsdl}
    Set Port    ${PORT}

    Set Headers    Content-Type    application/soap+xml
    Set Headers    Soapaction      ${EMPTY}
    Set Headers    Action          "${BASE_URL}/${SERVICE.name}/${METHOD}"

    ${result}          Call Soap Method     ${METHOD}

SudsLibraryExtension.py

代码语言:javascript
复制
import suds.bindings
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError

class SudsLibraryExtension(object):
    """
    Extension on the SudsLibrary

    """
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'    
    ROBOT_LIBRARY_VERSION = 1.0

    def __init__(self, LibraryName='SudsLibrary'):
        """SudsLibraryExtension can be imported with an optional argument.
        - ``LibraryName``:
          Default value for `LibraryName` is SudsLibrary if not given.
          The name can by any Library Name that implements or extends the
          SudsLibraryExtension.
        """        
        try:
            self.SudsLibrary = BuiltIn().get_library_instance(LibraryName)

        # This is useful for when you run Robot in Validation mode or load
        # the library in an IDE that automatically retrieves the documen-
        # tation from the library. 
        except RobotNotRunningError:
            pass

    def set_binding(self, binding, url):
        """Set Binding can be used to add a binding to the message.

        Example    Set Binding     SOAP-ENV    http://www.w3.org/2003/05/soap-envelope
        """
        suds.bindings.binding.envns = (binding, url)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53633191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档