我正在尝试验证下面的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')
在此功能中,所有事情都只通过了最后一步,即失败了“并且匹配/ == read('Excepted.xml')”。实际为“(不存在)”
答案 0 :(得分:0)
请在将来简化您的示例,不要像这样将整个工作转储到这里。
当您执行match /
时,您尝试从根开始匹配FULL XML。我建议您只匹配所需的部分并简化生活。
您可以将以下内容剪切并粘贴到新的Scenario:
中,然后尝试。您会看到一个错误,就是表列path
和value
应该是小写的。我还向您展示了如何将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>
"""