Quantcast
Channel: New board topics in SmartBear Community
Viewing all articles
Browse latest Browse all 20755

How do I assert one of the objects in an array meets a condition in SoapUI by using JSONPath

$
0
0

Let's say I have a response like below

 

{"errors": [{
   "code": "100",
   "message": "Message for 100",
  },

  {
   "code": "200",
   "message": "Message for 200",
  }

]}

 

I can assert the codes by using JSONPath like below:

 

  Expression: $.errors[0].code

  Expected result: 100

 

  Expression: $.errors[1].code

  Expected result: 200

 

The problem is that the order of the objects in the array may change, i.e. 200 occurs first and 100 occurs after. So, I have to assert something like "the errros should contain an error with code 100 while the error 100 can occur anywhere in the errors array". How do I do this?

 

Currently, I have to use Script assertion to achieve this and I am wondering if there is a better way.

 

Thanks.

 


Viewing all articles
Browse latest Browse all 20755

Trending Articles