1

I have below requirements, if anyone can help in understanding how I can achieve that.

  1. Conditionally want to change the path
  2. Conditionally want to change the payload
  3. Conditionally validate different response structure
  4. Conditionally skip an API call and move to next API call in a scenario containing multiple API hits

Stating example below on what I want to achieve, can we do this in karate syntax in feature file?

  path = 'v2/myapi/getlist'
else if (environment == stg)
 path = 'v1/myapi/getlist'```

similarly for payload and response validation as both might differ based on the environment we are executing test in.

Also want to conditionally skip an API call
```if(environment == dev)
 Given path
 When method get
 Then match 200```

Want to execute above api call only if environment is dev but skip and continue to next api call if it is any other environment

It would be really helpful if someone can help to achieve this
sumit
  • 91
  • 1
  • 1
  • 5
  • my honest opinion, please DON'T do this. reasons are given here: https://stackoverflow.com/a/54126724/143475 - if you want tips on conditional logic, please refer this answer: https://stackoverflow.com/a/50350442/143475 - if you still want to write tests the way you have indicated in your question, I recommend that you don't use Karate and evaluate other frameworks that are more like pure code (Java etc.) approaches - and there are built-in ways to skip tests based on environment: https://github.com/karatelabs/karate#environment-tags - next time please ask one question at a time – Peter Thomas May 18 '23 at 10:24

0 Answers0