2

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'")

  • def response = call read ('response.json')

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

  • def response = call read ('response1.json')

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

Appreciate any suggestions/directions.

Sara_N
  • 33
  • 1
  • 4

1 Answers1

1

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thank you for answering this promptly. The solution worked! I also made a slight change (added curly braces around the operation name) in the match statement as well. My updated mock.feature : Background: * def getCatTypes = function() {return karate.match("request contains {operationName: 'getCatTypes'}").pass} * def addCat = function() {return karate.match("request contains {operationName: 'AddCat'}").pass} Scenario: getCatTypes() * def response = call read ('getCatTypes.json') Scenario: addCat() * def response = call read ('addCat.json') – Sara_N Dec 16 '21 at 21:04