Forum Discussion

NickMitricka's avatar
NickMitricka
Occasional Contributor
6 years ago

ReadyAPI 2.8 - Using Smart Assertion for data coming in different order

I'm testing a webservice that has the potential to return values in different order depending on execution.

Example below shows an array for the email object, where email[0] is not always the type = home.

{
   "emails" : [
      {
         "type" : "home",
         "value" : "testEmailHome@gmail.com"
      },
      {
         "type" : "work",
         "value" : "testEmailWork@gmail.com",
         "primary" : true
      }
   ]
}

Is it possible to utilize Smart Assertions to validate this scenario:

emails[*][type] == "home"
emails[*][type] == "work"

I know that I should always get 2 emails, but need to validate I'm getting one with type==work and one with type==home.

 

*Note - I know this can be done with other assertions, but I'm curious specifically about the Smart Assertion feature.

  • richie's avatar
    richie
    Community Hero

    Hi NickMitricka 

     

    I haven't used Smart Assertions myself - but it launches the Message Content Assertion assertion that was available in earlier versions of ReadyAPI! and I looked at trying to use this a while back.

     

    Someone that knows the functionality better than I might have a different opinion, but I believe it doesn't support what you need it to do if I understand correctly.  Essentially you're saying the sequence of the type = home or type = work isn't constant - you know you'll get both in your response - but the sequence isn't fixed.

     

    The problem I believe is that the Message Content Assertion assertion uses XPATH or JSONPATH (depending on the type of the response) to verify a certain attribute displays a certain value.

    The 'Validation' column in the Message Content Assertion form doesn't provide any values that supports what you need.

     

    As I say - someone who knows the functionality better might have a different opinion - but looking at it - I dont think so

     

    nmrao  showed me a couple of script assertions to handle what you want - but that doesn't help you I'm afraid

     

    Cheers,

     

    rich

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      I am not aware of Smart Assertions and author of this question mentioned that he knows achieving what he needs using other ways.
      • richie's avatar
        richie
        Community Hero

        I understand - I was just highlighting that I think this is unachievable with the Message Content Assertion assertion

         

        cheers,

         

        rich