soapui免费版本断言请求=响应

时间:2017-10-25 07:33:11

标签: groovy match soapui assertions

我将传递任何memberid或活动卡进行匹配,以验证activecard(cardno)匹配的memberid传递。

 请求:

 <MemberID>${Property Looper#memberid}</MemberID>
 <CardNo>${Property Looper#ActiveCard}</CardNo>

预期结果:

 <ReturnMessage>Cardno not found</ReturnMessage> 

OR

 <ReturnMessage>SUCCESS</ReturnMessage>

如何设置断言来检查请求中的成员ID是否会检查与响应匹配?包含但不包含断言似乎不适合这种情况?

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

谢谢

编辑: after running the step

编辑2: after running script assertion
custom property added

2 个答案:

答案 0 :(得分:0)

您可以使用Script Assertion来实现相同目标。

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

  • 在某些情况下,您可能会期待card not found
  • 在某些情况下,您可能会期待SUCCESS

定义测试用例级自定义属性,比如EXPECTED_MESSAGE并根据具体情况提供适当的预期值。

为SOAP Request测试步骤添加以下脚本断言。

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

答案 1 :(得分:0)

让我们假设输出就像

if x! < 1000

您可以使用以下脚本断言

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

输出

def groovyUtils = new  com.eviware.soapui.support.GroovyUtils(context)
def response = groovyUtils.getXmlHolder("First Step#Response")

String x = response.getNodeValue("//*[local-name()='ReturnMessage']")

 if(x.contains("Cardno not found" ) || x.contains("SUCCESS"))
 {
  log.info "Success"
 }
 else
{
log.info " Fail"
}

Rao的方法也是正确的。只是如果你遵循这种方法,你必须有2个预期的结果自定义属性,因为你有2个属性。

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

2您可能必须在脚本中进行的更改。替换&#39;第一步&#39;与您的测试步骤的名称

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