Forum Discussion

LennSar's avatar
LennSar
Contributor
3 years ago

does NOT equal assertion

Hi there,

 

I need a not equal assertion to make sure a parameter has changes. Unfortunately I cannot find such a thing? Is there any assertion I could use to check a response to be not equal with the response from an earlier request? 

 

Thanks,

 

Lennart

  • Hey LennSar 

     

    I actually started using ReadyAPI with the same perspective as you did - i.e. we needed a tool that didnt require dev experience.  for the most part this is true - relatively speaking when comparing with the other tools out there - ReadyAPI is one of the best I feel for the license cost.  The advantage of the tie in with groovy/java is that it allows you to extend the existing embedded functionality just in case it doesnt do exactly what you need.  Even if ReadyAPI included a not exists assertion - sooner or later you'd come across another scenario which would require a little groovy/java.

     

    Anyway - yep I can stick the groovy together for you - I should highlight that I only know any due to me being taught by people like nmrao and ChrisAdams on this site.

     

    I was just wondering 2 things - so the Content-Type header says the response is json, but the payload coming back isn't in fact wellformed json at all.....it's just a single value?

     

    I know you screengrabbed the RAW tab - I'm intrigued by what's being displayed in the Outline or JSON tab?  If the content isn't being recognised as json - than we might have to cheat a little to extract the value (I'll get onto that later depending on your response).  Can you confirm what's being displayed in the JSON tab AND the Outline tab on the Response please?

     

     

    2nd thing I wanted to highlight - the 'Smart Assertion' function DOES have a 'not equals' assertion - (I'd forgotten about the Smart Assertion function cos I've only ever used it once) perhaps this could help? 😉 (although I'm wondering if it'll work with a malformed payload.....)

     

    Cheers,

     

    Rich

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi Lennart,

     

    I'm assuming you're using the licensed version of ReadyAPI.

    Personally, I jump to Groovy scripting as I've been using Groovy with ReadyAPI for several years.

    That said, there's usual more than one way to achieve the same thing.

    There are lots of standard assertions you can apply to a particular request without resorting to Groovy or scripting.  You can check for valid http statuses (200) or invalid (500), or depending on the use case, a valid http response may be a 500 if you're running some sort of negative request.

    You can check for content existing, make sure a particular value is present and all sort of things.  You can apply SLA type assertion that fail if the service doesn't return in, say, 200 millis.

    It's worth investing a little time to play with these.

    One of interest might be a 'Smart Assertion'.  Start with your second request and add a smart assertion.  Hopefully, Ready API will be able to pick out the value of interest. You can check values for equality, inequality, greater than, less than etc.etc.

    In the valid value column, Ready API tries to anticipate what you want.  You can overwrite the value to something else.  But, what you can do here is clear the cell, then right-click in the cell and there is an context option called Get Data.  This is probably one of the best Ready API features and is barely documented.  Selecting Get Data allows you to navigate through you test hierarchy and select a value to check against.  Using this, you could select the response from the first service call and check it against the second service call.  Because you've used 'Get Data' the value is not hard-coded.  ReadyAPI will dynamically pull this in.

    Have a play with it.  Because of the lack of key/value pairs, it might not help with this issue, but you will defiantely see how useful it is without resorting to scripting.  If this doesn't help, comeback and I'll see I can help.

    Regarding scripting in general.  Yes, ReadyAPI is really powerful and straightforward to getting started with, but I'm pretty sure there will be times where a script help.  IMHO, it is worth investing the time in learning some basic scripting, and this forum is an excellent place to get help.

    It's worth noting that the majority of people that help on here are not affiliated with SmartBear or employed, we're just users of ReadyAPI who can help others.  Bit like StackOverflow.

    • LennSar's avatar
      LennSar
      Contributor

      Sorry ChrisAdams,

      I've somehow overlooked your post.
      I am familiar with scripting like bash or python so I'm generally not afraig to deep dive into groovy. Especially because, as you said, there will always be things a tool can't do, while a script can. I will dig in it when I have to but with the lack of time I will try to avoid it and as you and richie pointed out: There is A LOT more capabilities when using the SmartAssertion that so far covers all my needs. So far 😉

      Thanks for your input and the info where you guys are coming from. I thought this is more a community forum like most chip manufactures over where customers ask question to the suppliers engineers. Knowing that's different I even more appreciate your help! 

       

      Thanks,

       

      Lennart

  • richie's avatar
    richie
    Community Hero
    Hey LennSar,

    Do you mean you wanna compare the whole response from one request to a second request, or just specific values from one to another?

    Cheers,

    Rich
  • richie's avatar
    richie
    Community Hero
    Hey LennSar,

    Before now, ive done this a groovy script.

    Fact is the ReadyAPI parameterises the whole response, so i reckon you can do it with a script assertion

    If you can indicate what your testcase object hierarchy is, along with details of the payloads, we'll sort out the script assertion.

    ChrisAdams/@KarelHusa/@nmrao will do a better job of the groovy than me though, if they fancy looking at this.

    Cheers,

    Rich
  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi, it should be straightforward to script this.

     

    Without having more details, I'd create a Groovy script step.  In it, I'd get the response from the two requests and run the not equals assertion....

     

    E.g.

    assertNotEquals(responseOne, responseTwo);

     

     

    • LennSar's avatar
      LennSar
      Contributor

      Hi richie, hi ChrisAdams,

       

      thanks for your answers!
      I'm not sure whether 'property' is the right term to use. Let me explain: 
      I have a json formatted response that does not have a key / value pair. What I see in ReadyApi is that in the RAW view I can see the expected string right below the header stuff. In the Overview view Ready API doesn't display anything (due to the missing key value pair I guess).

      What I want to do is to make sure that this string has changed, which probably takes a little more magic than that single line? 
      Here's a screenshot of what the response looks like:

      Finally I need to say/ask: We choose ReadyApi because the barrier of entry seemed really low as it didn't require having to learn a new programming language. We are currently trying to convince colleagues and other departments to switch to ReadyApi because of that and now this? I don't have the possibility to check whether a response is NOT a certain string without having to learn groovy? Well that's a problem!
      I have huge trouble digging into the ReadyApi conform syntax of groovy scripting. The examples on the documents page couldn't really help me, so I'd kindly ask you for a full script example.

      Here's an example project so we talk about the same instances of the hierarchy. Note that the request has a path-parameter {Level} (I hope that's the right expression). 

      Thanks a lot for taking the time!

       

      Cheers,

       

      Lennart

      • richie's avatar
        richie
        Community Hero

        Hey LennSar 

         

        I actually started using ReadyAPI with the same perspective as you did - i.e. we needed a tool that didnt require dev experience.  for the most part this is true - relatively speaking when comparing with the other tools out there - ReadyAPI is one of the best I feel for the license cost.  The advantage of the tie in with groovy/java is that it allows you to extend the existing embedded functionality just in case it doesnt do exactly what you need.  Even if ReadyAPI included a not exists assertion - sooner or later you'd come across another scenario which would require a little groovy/java.

         

        Anyway - yep I can stick the groovy together for you - I should highlight that I only know any due to me being taught by people like nmrao and ChrisAdams on this site.

         

        I was just wondering 2 things - so the Content-Type header says the response is json, but the payload coming back isn't in fact wellformed json at all.....it's just a single value?

         

        I know you screengrabbed the RAW tab - I'm intrigued by what's being displayed in the Outline or JSON tab?  If the content isn't being recognised as json - than we might have to cheat a little to extract the value (I'll get onto that later depending on your response).  Can you confirm what's being displayed in the JSON tab AND the Outline tab on the Response please?

         

         

        2nd thing I wanted to highlight - the 'Smart Assertion' function DOES have a 'not equals' assertion - (I'd forgotten about the Smart Assertion function cos I've only ever used it once) perhaps this could help? 😉 (although I'm wondering if it'll work with a malformed payload.....)

         

        Cheers,

         

        Rich