Reputation: 169
I need to mock an API using Karate Mock which accepts messages with Content-Type as below and respond accordingly
'Content-Type: application/x-www-form-urlencoded'
I tried to configure it in feature file as below but encountered below issue. I guess by default it is accepting JSON as the content-type, Is there any way to configure mock to read custom messages like this one.
Actual API call:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "elem_value=generic_value&address=" http://myhost:9090/api/resource_path
Mock feature file:
Scenario: pathMatches('/api/resource_path') && typeContains('urlencoded')
* def responseStatus = 200
* def response = read ('/payload/Success.json')
* print response
Actual Error:
Caused by: <eval>:1 ReferenceError: "generic_value" is not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1441)
at jdk.nashorn.internal.scripts.Script$43$\^eval\_.:program(<eval>:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449)
Upvotes: 2
Views: 276
Reputation: 58058
This should have been fixed in a newer version of Karate, please try upgrade.
I think it will be in 0.9.2 - https://github.com/intuit/karate/issues/649
Upvotes: 2