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

使用suds库在RobotFramework中测试soap1.2服务,soap,robotframework,webservice-client,suds,Soap,Robotframework,Webservice Client,Suds,我正在尝试使用RobotFramework测试SOAP1.2服务。到目前为止,我们只使用RobotFramework的suds库测试了SOAP1.1服务,而suds与SOAP1.2不兼容 向后兼容性是新服务的一个选项,但最好有一个更长期的解决方案。我不是一个经验丰富的程序员,虽然我可以编辑代码,如果告诉我编辑什么和在哪里 我们对使用suds的soap 1.2服务进行的测试中发生的情况是:suds无法解释它从web服务获得的响应,并给出以下错误:SAXParseException::159:229

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

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

我们对使用suds的soap 1.2服务进行的测试中发生的情况是:suds无法解释它从web服务获得的响应,并给出以下错误:SAXParseException::159:229:不匹配的标记

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

我在网上找到了一些片段,建议我可以让suds库与SOAP1.2一起用于我的RobotFramework测试。但我几乎没有编程经验,也不知道如何将这些代码片段整合到sud中。 有人评论这段话,说这解决了他在机器人框架和肥皂水方面的问题

有没有人愿意解释我是如何做到这一点的?我似乎无法独自解决这个问题。如有任何建议,将不胜感激

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()

短文中的代码段:

不支持SOAP 1.2绑定。开发早就停止了。因此,SudsLibrary也不支持它

我使用一种新方法观察到的一些差异是:

  • HTTP头
    内容类型
    • 1.2=
      “应用程序/soap+xml”
    • 1.1=
      “text/xml”
  • HTTP头
    • 1.2=
      操作
    • 1.1=
      SOAPAction
  • 信封名称空间
    • 1.2=
      ”http://www.w3.org/2003/05/soap-envelope“
    • 1.1=
      ”http://schemas.xmlsoap.org/soap/envelope/“
  • 在下面的示例中,针对每一个问题,分别实施了一个解决方案。内容类型可能被覆盖。可以添加操作,但不能删除SOAPAction。还可以使用扩展库覆盖名称空间。如果您的服务忽略SOAPaction头属性,那么这应该适用于您

    测试用例.机器人

    *** 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

    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)
    

    您使用的是哪种Python版本?验证1.1和1.2之间的关键区别是
    内容类型的HTTP头值已更改为
    'application/soap+xml'
    。这应该是你调查的重点。我在SudsLibrary方面的经验不太好,所以我建议尝试一个fork或评估一个定制实现。感谢您的回复。我们现在是2点7分。升级现在不是一个选项。出于测试目的,迄今为止,sud工作良好(robotframeworksudslibrary)。我曾尝试将HTTP头更改为application/soap+xml,但到目前为止,我还没有找到一种可行的方法。定制实现实际上就是我通过集成命名代码段所要做的。我只是不知道怎么做。非常感谢你的回答!我们正在使用的服务目前已恢复到1.1。一旦下一个SOAP1.2服务可用(应该在几周内),我将尝试解决方案并在完成后进行更新。