1

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

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Abhinav
  • 51
  • 9
  • The question isn't that clear. could you explain better or give example code of what you mean? – kaki gadol Jul 29 '19 at 07:54
  • @kakigadol i just updated the same explaining more descriptively. – Abhinav Jul 29 '19 at 08:23
  • @kakigadol to be more precise, i am working for an F&B application, which has inventory managed at server side, and we create order from clients. so i need to test that while creating an order, is the inventory updated properly or not. – Abhinav Jul 29 '19 at 08:26
  • you need to check `p1` variable exists? do you want to stop execution? can you add more details? – Ori Marko Jul 29 '19 at 14:20
  • @user7294900 i need to check the updated value of p1 from json extractors. Let me add more information. – Abhinav Jul 30 '19 at 01:45
  • @kakigadol I have updated the complete information now, u can plese check if you can help. Let me know, if u need payloads also. – Abhinav Jul 30 '19 at 06:38
  • @user7294900 hey...i have added more description with image of my test suite. Please see if you can help here. – Abhinav Jul 30 '19 at 06:39

1 Answers1

1

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)

Ori Marko
  • 56,308
  • 23
  • 131
  • 233