Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karate Framework : #notnull and #present are not working in case response is empty

Tags:

karate

My validation is to verify weather orgId appears in the response or not and that orgId should contain some value

The response that i am getting is Status code 200 and response body is empty.

Now I have below implementation

Then match $.orgId == '#present'
Then match $.orgId == '#notnull'

In this case the code passes, Ideally it should fail since response body is empty and orgId is not present in response. My question is why is the code getting passed with #present and #notnull even if the response body is empty

like image 219
Archit Goel Avatar asked Mar 03 '23 19:03

Archit Goel


1 Answers

You are definitely missing something. Try this in a fresh scenario and see it work. We are hard-coding response below, which is exactly equivalent to what happens at run-time, and by the way this is a great way for you to test assertions against different types of JSON (without making any HTTP calls):

* def response = {}
Then match $.orgId == '#present'
Then match $.orgId == '#notnull'

And this gives a failure as you expect:

assertion failed: path: $.orgId, actual: null, expected: '#present', reason: actual json-path does not exist

So if you still are stuck, follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

EDIT: if your response is an empty string but you were expecting JSON, just do this and it will fail the test, refer type-conversion: https://github.com/intuit/karate#type-conversion

* json response = response

But as mentioned in the docs, you should always try to match "full JSON" so this should work:

* def response = ''
Then match $ contains { orgId: '#notnull' }

EDIT: this will be fixed in 0.9.4 https://github.com/intuit/karate/issues/814

like image 193
Peter Thomas Avatar answered May 11 '23 09:05

Peter Thomas