如何在空手道中根据响应 header 应用 if 条件

How to apply if condition on the basis of response header in karate

当特定响应 header 存在时,我必须调用另一个功能文件。它失败了,因为当它进入 if 条件并且没有找到响应 header 它给出错误并且不执行该功能文件。如何在空手道中实现这一目标?

这个 header 的值是动态的。

* if (responseHeaders['APP-ID'][0] !=null) karate.call('classpath:resources/userData.feature@test1', { Id: Id , value : 'success' })

错误:

<<<<
org.graalvm.polyglot.PolyglotException: TypeError: Cannot read property "0" from undefined
- <js>.:program(Unnamed:1)

这会起作用:

* if (karate.get("responseHeaders['APP-ID'][0]")) karate.call('called.feature', { id: 'foo' })

如果您想了解其工作原理,请阅读文档中的 karate.get()

就是说 - 不要过度设计您的测试。请阅读: