1

So I have a response with a similar structure to the example below. Key2 eventually will change to a value that means my test can proceed, so I want to make sure that all values for Key2 are eventually "Test" by using retry until. I've tried to follow documentation to get something to work but not having much luck.

{
    "Array": [

        {
            "Key1": "Value1",
            "Key2": "Test"
        },
        {
            "Key1": "Value1",
            "Key2": "Test"
        }
    ]
}

Any help would be great. Thank you.

Solution:

And retry until karate.match("each response.Array contains { Key2: 'Test' }").pass
SDewar
  • 11
  • 2
  • next time, please have some respect for people trying to help you and make your JSON well-formed and valid. right now it is not. – Peter Thomas Sep 17 '21 at 12:01

1 Answers1

0

Try this, understand how it works and then you will know what to do:

* def response = 
"""
{
    "Array": [
        {
            "Key1": "Value1",
            "Key2": "Test"
        },
        {
            "Key1": "Value1",
            "Key2": "Test"
        }
    ]
}
"""
* def result = karate.match("each response..Key2 == 'Test'")
* assert result.pass
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thanks for the comment. Apologies about my malformed json in the first place. response..Key2 will also pick up any keys buried further in the tree right? I have the same key nested deeper which represent something different so ideally I want to ignore that and only check the Keys at Array[*].Key2 level. – SDewar Sep 17 '21 at 13:16
  • @SDewar try it and see. and then read the docs if needed, search for "json path" – Peter Thomas Sep 17 '21 at 13:42
  • 1
    Cheers. Got the following working reliably. - And retry until karate.match("each response.Array contains { Key2: 'Test' }").pass - just in case anyone else comes across the same problem. – SDewar Sep 20 '21 at 11:21