Forum Discussion

Kevin902's avatar
Kevin902
New Contributor
8 years ago

How do I create an assertion to check if the returned value is in a certain range? (REST)

Hey guys,

 

I am having problems with the following. I have a login webservice I'm trying to setup in SoapUI. I've added certain functions of the webservice like count the amount of accounts, show me all accounts etc. My question is how do I add an assertion that checks if the returned value is between, let's say for example, 1-10. So my request looks like this:

 

GET http://s0acaw0048o/cbs.login.beheer.service/count HTTP/1.1
Accept-Encoding: gzip,deflate
Host: s0acaw0048o
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAACwALAAWAAAAAgACAAIAQAADgAOABABAAAWABYAHgEAAAAAAAA0AQAANQIIIJvW8yio1UgUScLmnJW6aiehlOVAJiv/sU/FmzEJtuhl872ZJeEPo9sBAQAAAAAAABBO19NrndIBoZTlQCYr/7EAAAAAAgAIAEMAQgBTAFAAAQAWAFMAMABBAEMAQQBXADAAMAA0ADgATwAEAA4AYwBiAHMAcAAuAG4AbAADACYAUwAwAEEAQwBBAFcAMAAwADQAOABPAC4AYwBiAHMAcAAuAG4AbAAFAA4AYwBiAHMAcAAuAG4AbAAHAAgAEeDo02ud0gEAAAAAQwBCAFMAUAB0AHMAdABrAHYAaABuAFcAMABWAEsAQQBYADIAMQA2ADgAVAA=

 

And the response is:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
Date: Wed, 15 Mar 2017 09:09:18 GMT
Content-Length: 1

7

 

The number 7 is the current amount of accounts active. It's the method I am using now GET "activeAccountsInteger'. Since the response is on the JSON tab, I figured I would need JSONPath, but that option is not available to me, only Xpath.

 

So my question is:  How do I create an assertion to check if the returned value is in a certain range?

  • lakshmiarun's avatar
    lakshmiarun
    SmartBear Alumni (Retired)

    Hi,

     

    This can be done by using Groovy scripting.

     

    Click on Add assertions>For existence with script and script it using groovy.

     

    Thanks