Forum Discussion

vcdRob92's avatar
vcdRob92
Occasional Visitor
9 years ago

How do I create assertions manually for a REST JSON API in SOAPUI standard version

Hi,

 

I am very new with SOAPUI, hoand beginner working with APIS. How can I create assertions manua lly for JSON output for a REST API? when I clikc on Add Assertions, I get the the options for XML... XPAth mantch, Xquery match etc... I thought that this screen would automatically show options for JSON outputs?   I am trying to follow the tutorial  in this page but the instructions are for SOAPUI pro:

 

http://www.soapui.org/rest-testing/getting-started.html

 

and the attached is what I see when I try to add an assertion, so how do I create assertions for JSON?

 

Thanks!

5 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    Unfortunately, unlike the commercial / pro, open-source SoapUI doesn't have JSON Assertion types built in, but luckily this is easily provided via the (Groovy) Script Assertion type.

     

    For example you can quite easily:

    • Check JSON response properties using Json Slurper (nice and easy). Json Slurper is built into standard Groovy so there is no need to add any external libraries to SoapUI. Please see the final recipe in a article I wrote for an example SoapUI With JSON Slurper
    • Or alternatively you could use json-path (https://code.google.com/p/json-path/) as SoapUI pro does (this does require external libraries to be added, I could provide an example if needed).
    • To check JSON schema compliance you could use json-schema (http://json-schema.org/), again this is a little more involved in terms of requirining the json-schema libraries to be added. Still quite doable. Can discuss the code if required.

    If you're quite new to SoapUI then probably try the first option and let me know if you need any help.

     

    Cheers,

    Rupert

  • amarcilla's avatar
    amarcilla
    Occasional Contributor

     Hi vcdRob92

     

    did you finally manage?

    I'm in the same situation than you

    I will really apreciate some help

     

    Thanks a lot !!

    Anna

    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      Hi,


      In terms of my answer, things have changed since version 5.2.1 - there are now JSON Assertions!

       

      However, I think they will not show up as options unless the response content type is application/json or similar - see below:

       

      Does this help answer your question?

       

      Regards,

      Rupert

    • amarcilla's avatar
      amarcilla
      Occasional Contributor

      Hi rupert,

       

      You are right!.. The RESPONSE still doesn´t have content-type JSON.

      Still training before the REST services has finished

      btw, have you updated your book after Soap 5.2.1 is released?

       

      Thanks !

      anna

       

       

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi Anna,

         

        OK, so are you are happy with how to get access to the JSON Assertions? I just made a quick Mock to return an application/json response (as shown in the previous screenshot). If the response data isn't JSON then the JSON Assertions wont be enabled.

         

        Unfortunately there's no way to really update my book with version changes etc (apart from written a second edition), luckily most things remain the same in principle even when applied to Ready! API. To deal with missing parts of of my book, add new ideas and support readers, I have made an unofficial area of my blog http://rupertanderson.com/blog/soapui-bonus-recipes/ - if there are any ideas / questions relating to the book please feel free to add them here and I'll do my best to respond. The publisher would like me to write another book at some point, so any ideas you have could also end up there!

         

        Thanks,

        Rupert