assertor option when the response tree is changing

sansachiesansachie Posts: 20

we have case where the tree of SOAP response changes. Suppose we do get customer operation, in the response (first time hit) we get customer ID 1 as first child and if we hit second time we get same customer ID 1 as second child. this way if assert customer ID 1 as first child , my TC will pass for first time but, fail for the second run. How to handle such changes in the response structure using assertor

Comments

  • benken_parasoftbenken_parasoft Posts: 488 ✭✭✭
    edited July 2

    Here's an example XPath for a service that returns a list of books. Notice I select the first book, using an index of 1:

    /*:Envelope/*:Body/*:getItemByTitleResponse/*:Result/i[1]/title/text()
    

    Instead of hard coding an index of '1' I can use different criteria, like selecting the book with a particular id, for example:

    /*:Envelope/*:Body/*:getItemByTitleResponse/*:Result/i[id='4']/title/text()
    
  • sansachiesansachie Posts: 20

    This does not solve the challenge. per above example how will we address if ID is unique value that we get in response? Suppose we get 3 such IDs.. id=1 , id=2, id=3.
    in our response, the sequence of these IDs is not same every time ..
    id=1
    id=2
    id=3
    or
    id=2
    id=1
    id=3
    Like this the sequence changes every time and i will not be knowing the value of ID. However i will have the data banked value of such IDs from precious response which i will be using to assert in this response.

    Hope you got what query right.

  • benken_parasoftbenken_parasoft Posts: 488 ✭✭✭

    You are trying to create assertions for "customer ID 1", in't this right? In my example, I showed you how you can use an XPath that's based on ID as opposed to position. I believe you can also parameterize the ID in your XPath if needed. In other words, using my previous bookstore example, instead of i[id='4'] you could try i[id='${id_from_databank}'].

    Otherwise, please consider if you really need to validate all the customers. In that case, I wouldn't use the XML Assertor but would instead recommend using a Diff tool with "ignore element order" option selected.

  • sansachiesansachie Posts: 20

    for Diff to solve the issue, every time my response should be same. No? But in my use case we get different and unique values for each tag in the response. So i believe i cannot use one standard response as a reference in Diff tool.

    Also, i cannot parameterize the value for i as i[id='${id_from_databank}']. As in my response it might be expecting i[id='${id_from_databank 1 }'] or i[id='${id_from_databank 2 }'] since the response changes every time.

    please suggest.

  • benken_parasoftbenken_parasoft Posts: 488 ✭✭✭

    for Diff to solve the issue, every time my response should be same. No?

    I wouldn't be able to answer this without having some explanation about how you are getting the expected values for your assertions. If the values are dynamic, like pulled from a database or something, then that still isn't a problem. Both the Diff tool and XML Assertor are parameterizable.

    Also, i cannot parameterize the value for i as i[id='${id_from_databank}']. As in my response it might be expecting i[id='${id_from_databank 1 }'] or i[id='${id_from_databank 2 }'] since the response changes every time.

    Similarly, this answer depends on how you are getting the expected values for your assertions. For example, let's say the IDs for your control data are in some order and the IDs in your response are in a different order. You need them in the same order, or extract the expected values in the same order as the ones in your control source.

    please suggest

    Let's say you have control elements A-B-C, and your response has elements C-A-B. You can't just compare values in order since the order isn't the same. To get the order the same, you would have to sort or re-order the values. The other option is to extract elements from the response in the same order as the control values, using XPaths like I described earlier which are not based on element index.

    Of course, I'm only describing things in general terms here. How to solve this in your particular case is another question, and would probably require a having a bit more detail about how your tst is setup, what the response actually looks like, and how you are getting the expected values for building your assertions. Unfortunately, I probably can't help with that, as I am only able to provide quick answers on the forum. Maybe someone else can. Or you might also consider contacting Parasoft Support if you'd like them to look at your tst with you.

Sign In or Register to comment.