Forum Discussion

jknipp's avatar
jknipp
New Contributor
12 years ago

XQuery Match Assertion multiple elements

I have a test step that returns the following response. What I what to do is create a XQuery Match validation that validates each <applicationId> element contains the same value as I pass in the request. Basically the functionality of a for each loop to compare each element. How do I do this?


<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:findUserConceptByAppResponse xmlns:ns2="http://remote.fp.com/">
<return>
<applicationId>25</applicationId>
<id>2548</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2549</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2550</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2551</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2552</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2553</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2554</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2555</id>
</return>
<return>
<applicationId>25</applicationId>
<id>2569</id>
</return>
</ns2:findUserConceptByApplicationIdResponse>
</soap:Body>
</soap:Envelope>



This validates correctly for the first instance of the <applicationId> element but I want all of them to match.

declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns2='http://remote.tums.fp.com/';
matches(//ns2:findUserConceptByAppResponse[1]/return[1]/applicationId[1]/text(), '${#TestSuite#ApplicationId}')

1 Reply

  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Just a thought, but are you able to have multiple conditions, e.g. add the following...

    matches(//ns2:findUserConceptByAppResponse[1]/return[1]/applicationId[2]/text(), '${#TestSuite#ApplicationId}')
    matches(//ns2:findUserConceptByAppResponse[1]/return[1]/applicationId[3]/text(), '${#TestSuite#ApplicationId}')
    matches(//ns2:findUserConceptByAppResponse[1]/return[1]/applicationId[4]/text(), '${#TestSuite#ApplicationId}')