空手道-如何设置HTTP状态变量从何时步骤?



我通过使用DELETE方法的空手道API调用rest服务。当服务被执行时,我得到了预期的HTTP状态204。

When method DELETE
Then status 204

测试通过,但我需要存储该状态,以便在测试场景中进行进一步的步骤。

当我想将此状态设置为其他变量时,例如:

When method DELETE
* def responseStatus = status
Then status 204

测试失败,因为:


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

如何重用状态?

状态码已经作为一个"魔术"给你了。变量responseStatus。参考文档:https://github.com/karatelabs/karate#responsestatus

你当然可以这样做:

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

最新更新