Assert json parameter value in second response with respect to same first request

304 views Asked by At

App is related to an f&b business, I have following scenarios (api calls):

  1. Create Order - on creating an order of any food item (let it be X), inventory of which is updated at back-end (this value is under test, let it be P1)
  2. Get Inventory - (this call will fetch me the updated value of inventory of ordered item (X) i.e. inventory value, P1)
  3. Cancel Order - this will cancel the order, i created in my first call, and hence P1 should be rolled back.
  4. Get Inventory - Again i will hit this call to get the value, so as to verify that the inventory value of P1 has been updated properly.

In API call, (2) I extract P1 value using jp@gc Json Extractor and same I did for same call (4). Now as per my expectations, value obtained in both these extractors should be equal as order has been cancelled now.

To assert these values, I am using JSON Assertion , either I am making use of wrong assertion or lacking a big amount of information here.

May be there is something like I can save the value first in some variable, and then assert.

Image of my test suite: enter image description here

1

There are 1 answers

2
Ori Marko On BEST ANSWER

You can add JSR223 Assertion with checking different variables e.g. a and b:

if (!vars.get("a").equals(vars.get("b"))) {
    AssertionResult.setFailureMessage("message");
     AssertionResult.setFailure(true);
}

The script can check various aspects of the SampleResult. If an error is detected, the script should use AssertionResult.setFailureMessage("message") and AssertionResult.setFailure(true)