Sara_N
Sara_N

Reputation: 33

Intercepting multiple graphql operations in a karate UI scenario always returns the first response from mock feature

My scenario in the top feature file looks like this:

Scenario: Fetch a cat type id and create a cat

* driver.intercept({ patterns: [{ urlPattern: '*api/graphql*'}], mock: 
'Mock.feature' })

When I click on the button to add a cat (//first graphql call happens. This gets cat types from the mock as expected)

And input a name

And select the cat type

And click create  (//second graphql call happens here. But this returns the cat types again)

Then I see a success message

Here is the mock.feature:

Scenario: karate.match("request contains operationName: 'getCatTypes'")

Scenario: karate.match("request contains operationName: 'AddCat'")

We use karate standalone jar and on version v1.2.0.RC1 (tried with 1.1.0 as well).

Appreciate any suggestions/directions.

Upvotes: 2

Views: 147

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Your use of karate.match() is wrong, note that it does not directly return a boolean. Read this for more: https://stackoverflow.com/a/50350442/143475

Try this change:

Scenario: karate.match("request contains operationName: 'getCatTypes'").pass

I also think there are much better ways to do the above, so read this also: https://stackoverflow.com/a/63708918/143475

Upvotes: 1

Related Questions