1

One of my API's is returning,

"minStudentAge":12

For a one API out put there will be 5 ,6 "minStudentAge" tags with different integer value.

Is there any way to validate the integer value which is next to "minStudentAge" tag is in between 15 and 25?

2

Here are the steps:

  1. Prepare a request returning the data you need
  2. Create a Test Suite
  3. Create a Test Case within that Test Suite
  4. Add that request as the step to the Test Case
  5. Open that step editor
  6. In the bottom left corner click "Assertions"
  7. Click [+] (add) button
  8. In "Add Assertion" dialog select "Property Content" (right hand pane)
  9. In the list of shown matchers select which matcher will match (lol) your needs. For example you may want to count the number of nodes matching your conditions.
  10. Describe the JsonPath expression for your case. See reference here. The expression might depend on what the entire schema of your returned object is. Here is the example: $..[?(@.minStudentAge > 15 && @.minStudentAge < 25)]
  11. Specify the expected result. For example for JsonPath Count matcher it could be 1

Now you have the test case that asserts your field value.

UPD: As it turned out, there is an issue in Soap UI that breaks parsing of JsonPath expression if there is || (or) condition used. Hence, instead of using one assertion like this:

$.result.[?(@.minStudentAge < 15 || @.minStudentAge > 25)]

it is better to have two separate asserts specified for the test case:

  1. $.result.[?(@.minStudentAge < 15])
  2. $.result.[?(@.minStudentAge > 25])

This will work pretty much like the single condition with or operator, however this might be even more useful because when fail you will get more concrete error message for your test (that will fail if any of assertions fail).

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.