1

What I'm trying to do is hit a service twice in a row with a post of the same data. The idea here is to confirm that I can't have duplicate data, so I should get a 422 and a specific message in the response.

The test looked something like this:

When javaClient.createFoo(parameters)
And javaClient.createFoo(parameters)
Then status 422
And match $.message == "This is a duplicate."

It doesn't have a problem matching the status of the second call, but when I try to match the message (or any part of the response) it compares to the response from the first call.

I've tried making the second call a When, tried checking the status of the first call in between, but there must be something else that I'm missing.

Any ideas? Is there something special I need to do to clear the response?

Scott MacDonald
  • 115
  • 1
  • 8

1 Answers1

1

Unless the method step is called, Karate does not do anything. The use of javaClient.createFoo() (whatever that is) suggests that there are some fundamental problems in your use and understanding of Karate.

I suggest keep it simple and just repeat the method post with the same payload and it should work as you expect.

Also please read this: https://stackoverflow.com/a/54126724/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thanks for your quick response, and also, holy cow, who better to get a response from! I'm currently trying to work with some stuff that was written before I got a hold of it, and it sounds like I need to go back to those who did that work for answers. I read the article you posted and will definitely keep it in mind going forward! – Scott MacDonald May 05 '20 at 18:35
  • 1
    @ScottMacDonald phew, I'm glad I didn't vent more in this answer - thanks for looking out for how to improve ! – Peter Thomas May 05 '20 at 18:53