Forum Discussion

dmllc's avatar
dmllc
Occasional Contributor
14 years ago

multiple xpath expressions in an asseretion?

is it possible to have multiple xpath expression validations in a xpath assertion? for instance if I want to verify that several nodes of a soap response are being returned

Xpath Expression:
exists(//ns1:BasicData),
exists(//ns1:CorporateData)

Expected Results:
true
false


the above scenario does not work. is this possible or do i have to create a assertion for each node?

3 Replies

  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Hi,

    XPATH Assertion will have either pass or fail status. Logically it won't be much effective if you try to combine multiple expressions in one as the assertion will fail if even one of the expression fails. And you will have to dig inside to check which failed. There fore all these should be in different assertions.

    You can however write a script assertion and check for all the expressions. Initialize a counter to say 0 in your script. And increment that whenever you get a 'fail'. At the end, check for the value of counter. If its still 0 pass the script assertion otherwise fail it.

    Regards,
    Deepesh Jain
  • Hi,

    I guess the simplest way to do this would be using Logical Operator in your XPath assertion.
    something of this short
    (exists(//ns1:BasicData) and exists(//ns1:CorporateData))

    so this will return True only when both of these node will exists in response. Else assertion would fail.
    Or add 2 separate assertion for each node & whenever there is a failure of any Xpath assertion, it would lead to the failure of complete test step.

    Hope this will help.

    Best Regards,
    /Pradeep Bishnoi
    http://learnsoapui.wordpress.com