1

I would like to reuse a feature both for POST-ing and PUT-ing a JSON Object. In order to achieve that I am trying to use a condition in the call:

Given param admin = admin
And request role
When method (role.id == null) ? karate.POST : karate.PUT

The error I get:

no step-definition method match found for: method (role.id == null) ? karate.POST : karate.PUT

I checked the documentation and the examples and search for the solution here, but I did not find an answer to this question. Thanks in advance for the help.

1 Answers1

0

You can use a variable for the method step:

* def action = 'GET'
* url 'https://httpbin.org/get'
* method action

Other than that I have no suggestions. I strongly advise you to not do this kind of "re-use" as it leads to un-readable and un-maintainable tests. Please read this once: https://stackoverflow.com/a/54126724/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thanks, Peter. After reading the linked post and following the additional links inside that I am persuaded that I should not do this. By the way, thanks for developing Karate DSL, it is just awesome. – Miklós Szeles Feb 03 '22 at 14:25
  • @MiklósSzeles glad you like it - and thank you for this comment. to be very honest most people don't listen to this particular suggestion, great to hear that you took the time to understand the trade-offs – Peter Thomas Feb 03 '22 at 16:50