Search code examples
karatehttp-status-code-204

Karate - How to set HTTP status to variable from When step?


I'm calling a rest service through Karate API with DELETE method. When the service is executed, I am getting HTTP status 204 which is expected.

When method DELETE
Then status 204

Test is passing, but I need to store that status for furhter steps in test scenario.

When I want to set this status to other variable, like:

    When method DELETE
    * def responseStatus = status
    Then status 204

test failed because:


* def responseStatus = status
js failed:
>>>>
01: status
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "status" is not defined
- <js>.:program(Unnamed:1)

How can I reuse the status?


Solution

  • The status code is already given to you as a "magic" variable called responseStatus. Refer the docs: https://github.com/karatelabs/karate#responsestatus

    So you certainly can do things like this:

    * if (responseStatus == 204) karate.call('some.feature')