首页 > 解决方案 > 如何验证来自 SOAP 响应的多个输出

问题描述

我正在尝试验证下面的 XML SOAP 响应,但它不起作用。请让我知道正确的方法。如果需要更多信息,请告诉我。

响应 XML:

<GetTariffsInfoResult>
  <Status>
    <StatusCode>0</StatusCode>
    <StatusDescription>SUCCESS</StatusDescription>
  </Status>
  <OutputParameterSets>
    <OutputParameterSet>
      <OutputParameters>
        <OutputParameter>
          <Name>COMP_AVAILABLE</Name>
          <Value>TRUE</Value>
        </OutputParameter>
        <OutputParameter>
          <Name>ILEC_VENDORNAME</Name>
          <Value>COMP1</Value>
        </OutputParameter>
        <OutputParameter>
          <Name>ABC</Name>
          <Value>FALSE</Value>
        </OutputParameter>
        <OutputParameter>
          <Name>TEST</Name>
          <Value>Identical</Value>
        </OutputParameter>
      </OutputParameters>
    </OutputParameterSet>
  </OutputParameterSets>
</GetTariffsInfoResult>

特征

    Scenario: Check Request and Respone xml

     * set /Envelope/Body/GetTariffsInfoResponse/GetTariffsInfoResult
              | Path                | Value   |
              | OutputParameter[1]/Name  | 'QOS_AVAILABLE'   |
            | OutputParameter[1]/Value | 'True'  |
            | OutputParameter[2]/Name  | 'ILEC_VENDORNAME'   |
            | OutputParameter[2]/Value | 'CENTURYTEL OF MW-WISCONSIN LLC  DBA CENTURYLINK - NORTH'  |
            | OutputParameter[3]/Name  | 'QC'   |
            | OutputParameter[3]/Value | 'FALSE'  |
            | OutputParameter[4]/Name  | 'ELA_PREMIER_TYPE'   |
            | OutputParameter[4]/Value | 'Identical'  |
            | OutputParameter[5]/Name  | 'QOS_ALIGNMENT'   |
            | OutputParameter[5]/Value | 'Y'  |
            | OutputParameter[6]/Name  | 'QOS_IDENTICAL'   |
            | OutputParameter[6]/Value | 'Y'  |
            | OutputParameter[7]/Name  | 'QOS_MEDIUM'   |
            | OutputParameter[7]/Value | 'Y'  |
            | OutputParameter[8]/Name  | 'QOS_NONE'   |
            | OutputParameter[8]/Value | 'Y'  | 
            #|path



        Given request read('request.xml')
        When soap action 'XYZ'
        Then status 200
        And match /Envelope/Body/GetTariffsInfoResponse/GetTariffsInfoResult/Status/StatusCode == 0
        And match /Envelope/Body/GetTariffsInfoResponse/GetTariffsInfoResult == read('Excepted.xml')
        And print 'response: ', response
    And match / == read('Excepted.xml')

在这个特性中,一切都通过了,只有最后一步失败了“And match / == read('Excepted.xml')”。将实际抛出为'(不存在')

标签: soapkarate

解决方案


请在将来简化您的示例,不要像这样将您的整个工作都丢在这里。

当你这样做时,match /你试图从根开始匹配 FULL XML。我建议你只匹配你需要的部分,让生活变得简单。

您可以将以下内容剪切并粘贴到新的中Scenario:并尝试。你会看到你犯的一个错误是表格列pathvalue应该是小写的。我还向您展示了如何使用 XML 本身作为预期结果,而不是痛苦地创建表。仔细阅读文档并参考此文件以获取良好示例:xml.feature

* def response = 
"""
<GetTariffsInfoResult>
   <Status>
      <StatusCode>0</StatusCode>
      <StatusDescription>SUCCESS</StatusDescription>
   </Status>
   <OutputParameterSets>
      <OutputParameterSet>
         <OutputParameters>
            <OutputParameter>
               <Name>COMP_AVAILABLE</Name>
               <Value>TRUE</Value>
            </OutputParameter>
            <OutputParameter>
               <Name>ILEC_VENDORNAME</Name>
               <Value>COMP1</Value>
            </OutputParameter>
            <OutputParameter>
               <Name>ABC</Name>
               <Value>FALSE</Value>
            </OutputParameter>
            <OutputParameter>
               <Name>TEST</Name>
               <Value>Identical</Value>
            </OutputParameter>
         </OutputParameters>
      </OutputParameterSet>
   </OutputParameterSets>
</GetTariffsInfoResult>
"""

* set expected /OutputParameters
    | path                     | value   |
    | OutputParameter[1]/Name  | 'COMP_AVAILABLE'   |
    | OutputParameter[1]/Value | 'TRUE'  |
    | OutputParameter[2]/Name  | 'ILEC_VENDORNAME'   |
    | OutputParameter[2]/Value | 'COMP1'  |
    | OutputParameter[3]/Name  | 'ABC'   |
    | OutputParameter[3]/Value | 'FALSE'  |
    | OutputParameter[4]/Name  | 'TEST'   |
    | OutputParameter[4]/Value | 'Identical'  |

* match /GetTariffsInfoResult/OutputParameterSets/OutputParameterSet/OutputParameters == expected

* match /GetTariffsInfoResult/OutputParameterSets/OutputParameterSet/OutputParameters == 
    """
     <OutputParameters>
        <OutputParameter>
           <Name>COMP_AVAILABLE</Name>
           <Value>TRUE</Value>
        </OutputParameter>
        <OutputParameter>
           <Name>ILEC_VENDORNAME</Name>
           <Value>COMP1</Value>
        </OutputParameter>
        <OutputParameter>
           <Name>ABC</Name>
           <Value>FALSE</Value>
        </OutputParameter>
        <OutputParameter>
           <Name>TEST</Name>
           <Value>Identical</Value>
        </OutputParameter>
     </OutputParameters>
    """

推荐阅读