cygne
cygne

Reputation: 547

How to use 'Ignore or Validate' in JSON file (karate framework)?

I have to verify that each response is in correct format. I've put in my feature:

And match each response contains { id: '#string', name: '#string', phone: '#number' etc..}

But I would like to put this in a JSON file, beacuse I need it several times in different features. When I use 'Ignore or Validate' tags in JSON file, it doesn't work. Is it possible to do this?

Upvotes: 1

Views: 2062

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58078

Yes why not. First place the following in a file called item-schema.json.

{ "id": "#string", "name": "#string", "phone": "#number" }

Now all you need to do is:

And match each response contains read('item-schema.json')

Please go through the documentation of Reading Files carefully.

Upvotes: 1

Related Questions