开发者

Soapui & Xpath : assertion for a simple node

开发者 https://www.devze.com 2022-12-25 12:59 出处:网络
I\'m currently using SoapUI Free edition 3.2-beta 2. And I have a weird problem with a Xpath assertion:

I'm currently using SoapUI Free edition 3.2-beta 2. And I have a weird problem with a Xpath assertion:

I have this in response:

(...) And I'm using this xpath to assert that the "niveau" with id='2' is in the response:

Xpath expression;

//*:niveau[@id='2']

And the expected result is:

<mod0911:niveau id="2" libelle="Immatriculation" ordre="0" taille="0"/>

But I have this error message: XPathContains comparison failed开发者_运维百科, expecting [ ], actual was [null]

But if I try this :

exists(//*:niveau[@id='2'])

And the expected result is: True It works !!?

But this syntax is quite difficult to read & maintain & I would like to use the 1st syntax (I've tried to ignore namespace, add them... still doesn't work).

Any ideas?

Regards


You can use FirstObject XML Editor tool to generate the Xpath.It will automatically generate the XPath for you selection like you are doing in soapUI Pro and then you can use that Xpath in your soapui free version.


The XPath that you declare is actually run against the XML in the response. Then it compares it against the text in "Expected Result".

I'm not 100% sure what you're trying to do. Given this response:

<root>
  <a>
    <b id="2" />
  </a>
  <c>
  </c>
</root>

If you put this in the "Declare": //b[@id=2], it will run that XPath against the XML. That XPath (untested) should select just the <b> element.

Then your "Expected Result" should be: <b id="2" />.


Give the pro version trial a spin, and you'll see that it's got a nice xpath expert built-in. With a sample request present, you can just pick the value that you're looking for and it'll generate the xpath and show you the value. Very cool. Copy/paste the xpath back into the free version and you're all set. Or, if you're like me, push harder for your boss to buy the Pro version for you.


You should include the XML tags not only the value of the node.

If you change your expectation from [ ] to <nodeName id=2 /> it should work.


You can use assertions: //b[@id='2'] or //b[@id=2]

Expected Result:

http://i.stack.imgur.com/3o2xx.png

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号