Forum Discussion

Donkey2017's avatar
Occasional Contributor
7 years ago

script assertion

Hi, not being a programmer could anyone suggest a way to check if the property "apples" has a number rather than just null for example. So below is the result of running a test. I can easily ask SOAP to check if there is an item called "apples" but I have no idea how to ask if "apples" equals a numerical value- any value not just 111.




{      "apples": 111,  


}, my own language.... I have a test in SOAP- one element of that test = "apples". I want to add a SCRIPT Assertion that checks that the test has created a Value for "apples" and not just a blank or "0".



thanks in advance

.....almost total non-programmer

  • nmrao's avatar
    7 years ago
    //Below Script Assertion should do the job
    def json = new groovy.json.JsonSlurper().parseText(context.response) //check id is number assert instanceof Integer, 'id is not integer type' assert 0 <, 'id is not a positive number'

7 Replies

    • Donkey2017's avatar
      Occasional Contributor

      Thanks Rao, below is what is returned after running the test:

         "CONTENT":    {
            "FILTERS": [],
            "asset_id": null,
            "asset_subtype": "xxxxxx",
            "asset_type": "xxxxxxx",
            "cost_multiplier": 0,
            "created_date": 20170602,
            "created_time": 153701,
            "effective_date": 20201123,
            "expiry_date": 20221101,
            "id": 114,
         "message": "Modifier successfully saved.",
         "modifier_id": 114,
         "status": "OK"


      Associated with this test are 2 simple assertions:

      1. Valid HTTP Status Code

      2. JsonPath ExistenceMatch---- here I just check ID exists; which it does -114


      It is the ID I am most interested in but knowing that ID is there is kind of pointless if I cannot check that a value has been created for it. I can make an error with the input so and ID result is not created but the assertion would still be valid- ID would still be there but empty.

      I need to check that a value has been produced- it could be 1 or 99999999 so long as an ID value has been produced.

      I did look at your link but I simply do not understand enough to apply it in an useable way.



      • nmrao's avatar
        Champion Level 3
        You mean to say value should be in the range between x and y (x, y belongs to integer)