script assertion
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
{
"CONTENT":
{ "apples": 111,
},
.......in 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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way, below are some examples using json.
https://github.com/nmrao/groovyScripts/tree/master/json
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Regards
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rao, no it does not need to be between any range in particular- it just has to be a number- any number; so long as it is not "null" or nothing..... as in "".
I just need to check that an integer has been created for the item ID.
Thanks
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
//Below Script Assertion should do the job
def json = new groovy.json.JsonSlurper().parseText(context.response) //check id is number assert json.CONTENT.id instanceof Integer, 'id is not integer type' assert 0 < json.CONTENT.id, 'id is not a positive number'
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OMG! Thanks so much Rao..... that did the trick. Now I'll try to apply your script to other conditions...
Regards
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
