Groovy soapui自由版本断言请求=响应

Groovy soapui自由版本断言请求=响应,groovy,match,soapui,assertions,Groovy,Match,Soapui,Assertions,我将传递任何要匹配的memberid或活动卡,以验证活动卡(cardno)是否与已传递的memberid匹配。 请求: <MemberID>${Property Looper#memberid}</MemberID> <CardNo>${Property Looper#ActiveCard}</CardNo> ${Property Looper#memberid} ${Property Looper#ActiveCard} 预期结果: &

我将传递任何要匹配的memberid或活动卡,以验证活动卡(cardno)是否与已传递的memberid匹配。

请求:

 <MemberID>${Property Looper#memberid}</MemberID>
 <CardNo>${Property Looper#ActiveCard}</CardNo>
${Property Looper#memberid}
${Property Looper#ActiveCard}
预期结果:

 <ReturnMessage>Cardno not found</ReturnMessage> 
Cardno未找到

成功
如何放置断言来检查请求中的成员id是否与响应匹配?contains和not contains断言在这种情况下似乎不能很好地工作

我希望即使匹配失败也能通过测试,因为最终目标是确保错误不是来自数据(测试通过与返回状态无关),而是来自应用程序

谢谢

编辑:

编辑2:

您可以使用
脚本断言来实现相同的功能

根据描述,断言应该能够处理以下两种情况:

  • 在某些情况下,您可能希望
    卡未找到
  • 在某些情况下,您可能期望
    成功
定义测试用例级自定义属性,例如
EXPECTED\u MESSAGE
,并根据具体情况提供适当的预期值

为SOAP请求测试步骤添加以下脚本断言

//Check if the response is received
assert context.response, 'Response is empty or null'

//Parse the response and find the ReturnMessage value
def actualMessage = new XmlSlurper().parseText(context.response).'**'.find{it.name() == 'ReturnMessage'}?.text()
log.info "Return message from response: $actualMessage"

//Read the expected message from custom property
def expectedMessage = context.expand('${#TestCase#EXPECTED_MESSAGE}')

//Verify with actual value
assert actualMessage == expectedMessage

您可以使用
脚本断言
实现同样的效果

根据描述,断言应该能够处理以下两种情况:

  • 在某些情况下,您可能希望
    卡未找到
  • 在某些情况下,您可能期望
    成功
定义测试用例级自定义属性,例如
EXPECTED\u MESSAGE
,并根据具体情况提供适当的预期值

为SOAP请求测试步骤添加以下脚本断言

//Check if the response is received
assert context.response, 'Response is empty or null'

//Parse the response and find the ReturnMessage value
def actualMessage = new XmlSlurper().parseText(context.response).'**'.find{it.name() == 'ReturnMessage'}?.text()
log.info "Return message from response: $actualMessage"

//Read the expected message from custom property
def expectedMessage = context.expand('${#TestCase#EXPECTED_MESSAGE}')

//Verify with actual value
assert actualMessage == expectedMessage

让我们假设输出如下

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>  
<ReturnMessage>SUCCESS</ReturnMessage>   
</soap:Body>
</soap:Envelope>
输出为

Sat Oct 28 15:22:02 IST 2017:INFO:Success
拉奥的方法也是正确的。只是,如果您采用这种方法,那么您必须有两个预期结果自定义属性,因为您有两个属性

您可能必须在断言之前使用if条件,因为1断言将失败,因为您的结果将是“Cardno not found”或“SUCCESS”

2您可能必须在脚本中进行的更改。将“第一步”替换为测试步骤的名称


更改getNodeValue步骤以到达实际位置

假设输出如下

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>  
<ReturnMessage>SUCCESS</ReturnMessage>   
</soap:Body>
</soap:Envelope>
输出为

Sat Oct 28 15:22:02 IST 2017:INFO:Success
拉奥的方法也是正确的。只是,如果您采用这种方法,那么您必须有两个预期结果自定义属性,因为您有两个属性

您可能必须在断言之前使用if条件,因为1断言将失败,因为您的结果将是“Cardno not found”或“SUCCESS”

2您可能必须在脚本中进行的更改。将“第一步”替换为测试步骤的名称


更改getNodeValue步骤以到达实际位置

是整个响应还是只是部分响应?@Rao只是部分响应。如果通过,它将显示卡片信息。请检查答案,看看是否有帮助。新手,你有机会尝试解决方案吗?@Rao几天前我刚刚开始使用这个工具,我还在想答案。我得到了这个错误“assert actualMessage==expectedMessage | | | | null | SUCCESS false”。我添加了自定义属性是整个响应还是部分响应?@Rao只是部分响应。如果通过,它将显示卡片信息。请检查答案,看看是否有帮助。新手,你有机会尝试解决方案吗?@Rao几天前我刚刚开始使用这个工具,我还在想答案。我得到了这个错误“assert actualMessage==expectedMessage | | | | null | SUCCESS false”。我确实添加了自定义属性df response=groovyUtils.getXmlHolder(“MemberID匹配#ResponseAsXML”)字符串x=response.getNodeValue(“//*:ReturnMessage”),我编辑了这两个字符串。我得到了一个意外的错误元素CDATA您可以尝试与我喜欢的响应相同的方法吗。getNodeValue(“/*[local-name()='ReturnMessage'])我能够使它工作。用于测试上述代码。。您可以将上面的代码粘贴到任何响应中,并将测试步骤(不是请求)命名为“MemberID匹配”,然后将上面的代码放入下一个groovy步骤您将不会得到CData errordef response=groovyUtils.getXmlHolder(“MemberID匹配#ResponseAsXML”)字符串x=response.getNodeValue(“/*:ReturnMessage”),我编辑了这两个步骤。我得到了一个意外的错误元素CDATA您可以尝试与我喜欢的响应相同的方法吗。getNodeValue(“/*[local-name()='ReturnMessage'])我能够使它工作。用于测试上述代码。。您可以将上面的代码粘贴到任何响应中,并将测试步骤(不是请求)命名为“MemberID匹配”,然后将上面的代码放在下一个groovy步骤中—您将不会得到CData错误