1

I have to call another feature file when a particular response header exists. It is failing as when it goes to if condition and doesn't find that response header it gives error and doesn't execute that feature file. How to achieve this in Karate?

The value of this header is dynamic.

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

Error:

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

1 Answers1

1

This will work:

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

Read up on karate.get() in the documentation if you'd like to understand how this works.

That said - don't over-engineer your tests. Read this please: https://stackoverflow.com/a/54126724/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thanks @Peter this is working as expected. You are right but our few APIs are dependent on one and other and I am still thinking on how to optimize this. :( – Maddy Oct 15 '21 at 17:02