Forum Discussion

rymliam's avatar
rymliam
New Contributor
2 years ago

Assert any array node equals

Situation: I have an API under test where one of the endpoints allows me to POST some object with a bunch of values. To test the backend fully I need to check that the object can be retrieved, but the only GET endpoint I can use returns an array of ALL of these object created. The object I just created could be anywhere in this array.

 

Problem: I cannot figure out how to get ReadyAPI to assert that any object in the array matches what I input. Using say, Smart Assertion, I can assert that the object at index 13 equals the my input, but the object I created in the POST might be at index 20, or 4000, or 0.

 

I like the functionality of Smart Assertion but I can't figure out how to get it to assert that the correct object exists anywhere in the array returned from the GET. Is this possible?

2 Replies

  • richie's avatar
    richie
    Community Hero
    Hey rymliam,

    I've just had a look at Smart Assertion (ive only used it a couple of times), but i dont think it supports what youre looking for. Maybe one of the other forum members might be able to help instead.

    However! Would you be open to using other assertion types like a script assertion? I use script assertions for the scenario youre talking about. If youre gonna use the script assertion option, youre gonna need to use xpath or jsonpath to assert the array contains the object content you want to verify is present.

    If you dont want to use a script assertion, you could try using the contains assertion, but i think ita tailored for xml not json.

    Cheers,

    Rich
    • rymliam's avatar
      rymliam
      New Contributor

      Thanks. Yeah I've tried a few things that kinda-sorta work, but was hoping there'd be a one click WYSIWIG solution without resorting to scripting as I have quite a bit of this kind of stuff to do, and it's beneficial if it's easy for others to understand.

       

      Can't quite believe that this functionality doesn't exist, I ran into this issue on probably the second API endpoint of the project, and I know it's a super common occurrence anywhere there's JSON used. I'll see what I can do with script assertions as a backup if there's no alternative in the meantime.