1
votes

I will pass any memberid or active card for matching to verify activecard(cardno) matches memberid passed.

Request:

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

Expected result:

 <ReturnMessage>Cardno not found</ReturnMessage> 

OR

 <ReturnMessage>SUCCESS</ReturnMessage>

How to put assertions to check if the member id in request will check matching with response? contains and not contains assertions seems like not working that well for this condition?

and i want the test to be passed even if the matching failed as the ultimate goal is to make sure the error is not from the data (the test pass regardless the return status) but the application.

Thanks

Edit: after running the step

Edit 2: after running script assertion
custom property added

2
Is that the whole response or just part of it? - Rao
@Rao just part of it. it will show card info if it passes. - AskNAnswer
Please check the answer to see if that helps. - Rao
NewBieMandy, have you got chance to try the solution? - Rao
@Rao im still figuring out on the answer as i just start using this tool days ago. i got this error "assert actualMessage == expectedMessage | | | null | SUCCESS false" . i did add custom property - AskNAnswer

2 Answers

0
votes

You can use Script Assertion to achieve the same.

Based on the description, the assertion should be able to handle both below cases :

  • some case, you may expect card not found
  • some case, you may expect SUCCESS

Define test case level custom property, say EXPECTED_MESSAGE and provide appropriate expected value depending on the case.

Add below script assertion for the SOAP Request test step.

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

Let us assume the output is like

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

you can use the below script assertion

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

output is

Sat Oct 28 15:22:02 IST 2017:INFO:Success

Rao's approach is also correct. Its just that if you are following that approach you have to have 2 expected result custom properties since you have 2 properties.

You may have to use if condition before assertion as 1 assertion will fail because your results would be either "Cardno not found" or "SUCCESS"

2 Changes you might have to make in the script. replace 'First Step' with the name of your teststep

change the getNodeValue step to reach the actual place