0

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 :

  * def booktypes = ['fiction','non-fiction']
  * def schema = { type: '#? booktypes.contains(_)' }
  * match response contains schema
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
roudlek
  • 160
  • 9

1 Answers1

2

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().

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    that correct sir, thank you, i would never know this if you didn't tell me, Documentation should be updated ! – roudlek Jul 21 '23 at 17:52
  • sir i would like to ask here cause they stopped me from asking : how can i reuse a variable in a scenario in another scenario, i got the generated access token but i cannot use it in the next scenario – roudlek Jul 22 '23 at 12:48
  • 1
    @roudlek read this please: https://stackoverflow.com/a/46080568/143475 – Peter Thomas Jul 22 '23 at 14:45