问题
I have a webService that returns certain values. I know what those values will be. I want to pick them out of the XML and if those values are true I want the assertion to pass. Imagine that my test passes if I get this result... How can I assert that that is the case?
<BasicPersons>
<id>4</id>
<firstName>Patricia</firstName>
<middleName>A</middleName>
<lastName>Cluss</lastName>
</BasicPersons>
<BasicPersons>
<id>5</id>
<firstName>Benjamin</firstName>
<middleName>L</middleName>
<lastName>Handen</lastName>
</BasicPersons>
<BasicPersons>
<id>6</id>
<firstName>Ellen</firstName>
<lastName>Frank</lastName>
</BasicPersons>
<BasicPersons>
回答1:
SoapUI provides XPath assertion for test steps that extracts XML element from the response and compare it with expected data.
Let's take you XML fragment as an example (I added root element to make it well-formed). First create in SoapUI new Test Request
step and fill it with request XML. Let's then check whether response contains BasicPersons element with id=4 and all other specified fields. Add new assertion XPath Match
from Property Content
group. Then type in the expression for the check. Here is what I get:
boolean(/root/BasicPersons[id=4 and firstName="Patricia" and middleName="A" and lastName="Cluss"])
Expected Result
shall be true
if XPath matches XML response. The assertion fails otherwise.
You may create several assertion for testing several persons from your response.
回答2:
A xpath expression like...
((//*:BasicPersons[1]/*:middleName)='A' and (//*:BasicPersons[1]/*:firstName)='Patricia') and so on for other fields)
This will return TRUE when all condition will match the response.
来源:https://stackoverflow.com/questions/13611683/how-to-get-certain-expected-values-using-soap-ui-xquery-matches