Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

match each response contains a property that can be value1 or value2 in karate

i get this as response:

[
{
    "id": 1,
    "name": "The Russian",
    "type": "fiction",
    "available": true
},
{
    "id": 2,
    "name": "Just as I Am",
    "type": "non-fiction",
    "available": false
},
{
    "id": 3,
    "name": "The Vanishing Half",
    "type": "fiction",
    "available": true
}
]

how can i match that all responses have type with either ‘fiction’ or ‘non-fiction’

i tried this :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  * def booktypes = ['fiction','non-fiction']
  * def schema = { type: '#? booktypes.contains(_)' }
  * match response contains schema

>Solution :

This will work:

* def types = ['fiction', 'non-fiction']
* match each response contains { type: '#? types.includes(_)' }

The JS equivalent for the Java contains() is unfortunately named includes().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading