Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
17 years ago

Assertion Question

Hello,
I guess I am the only one to ask questions in the this forum
I have question about assertions.  Below is part of a response from my web services.


                2211
                                CustomGrid_InvalidCustomGridNameFormat
               



                  2203
                 
                  NPE
                 



In the response message I expect only ErrorCode-->2211 so I have an XpathMatch assertion for that. However, as you can see in the response above, I got more than one ErrorCode which is not the expected behavior of my web service. There should only have been one error code.

Is there a way I can catch this kind of error through some assertion.

Thanks

Ali

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    sure, add an xpath assertion containing

    count( //ErrorCode )

    and set the expected value to 1

    or you can set the xpath expression to

    count( //ErrorCode ) = 1

    and set the expected value to

    true

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • alibaba82's avatar
    alibaba82
    Super Contributor
    Ole,
    I added count(//Error) under 'Xpath Expression' and '1' under 'Expected Results. When I press 'Test' I get

    XpathContains assertion failed for path[count(//Error)]:comparisonFailure:expected:<1> but was:<0>

    Shouldn't I get
    ....but was:<2>
    since i have 2 errors in the response.

    Thanks

    Ali
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Ali,

    maybe you need a namespace prefix, can you show the entire message? Alternatively, go to the outline editor for the response, right-click on the Error node and select "Add Assertion -> For Count", which should create the correct xpath expression for you.. (see http://www.soapui.org/userguide/functio ... ion_Wizard)

    regards,

    /Ole
    eviware.com
  • alibaba82's avatar
    alibaba82
    Super Contributor
    Thanks for the quick response Ole. I wasnt aware of the assertion wizard. Example works now

    - Ali