shrik18
shrik18

Reputation: 137

Karate does not seem to retain xml format in few scenarios

I tried following:

def isJson = false
xml payload_xml = read(some.xml)
json payload_json = read(some.json)
def payload = isJson == true ? payload_json : payload_xml

Given url someURL
Given request payload
When method post

turns out the payload is now payload_xml but in json format.

Also when I use single xml payload to consecutively call same abstract feature which has

Given url someURL
Given request payload
When method post

the second time payload is in json format.

Are there issues or am I doing something wrong?

Upvotes: 1

Views: 99

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

This line will always return JSON, because Karate will default JS evaluation like so:

* def payload = isJson == true ? payload_json : payload_xml

So figure out another approach. I feel you are over-complicating your test, and I recommend splitting into 2 scenarios. Please read this answer: https://stackoverflow.com/a/54126724/143475

There is no way to conditionally cast JSON to XML. You can work-around by calling a second feature. If you still see issues, follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

EDIT: maybe all you need to do is this:

* def payload == isJson == true ? read('some.json') : read('some.xml')

EDIT2: this will be easier in 0.9.6 onwards:

a) https://stackoverflow.com/a/62856565/143475

b) https://github.com/intuit/karate/issues/1202

Upvotes: 1

Related Questions