JSON assertion validation for status code 200.

divyangdivyang Posts: 8

My script reads test data from excel which also has a status code( expected result) column in it. Scripts fetches data from excel and compares it with status code to validate. Since output of my API is generated in JSON format, I am using JSON asserter to validate status code. The problem that I am facing is for a scenario which successfully execute with status code 200. There is no status code being captured in “Tree” in JSON Asserot  Expected JSON tab. it works fine for other status code(400,404,500). Any suggestion how to handle this situation?

Comments

  • divyangdivyang Posts: 8

    here is an attachment for the status code other than 200 , which is not being captured in "Tree"

    200.png 29.6K
  • jakubiakjakubiak Posts: 384 admin

    First create an Occurrence Assertion that validates that the number of instances of the status element is equal to 1. Then create a Value/Numeric Assertion that validates the value of the status code. Lastly, create a Conditional Assertion that uses the Occurrence Assertion as the "if" and the Value/Numeric Assertion as the "then". This will have the effect that the Value/Numeric Assertion will only get run if the status element is present in the response.

  • divyangdivyang Posts: 8

    Thank you for your quick response. Actually i want to validate status code in header section against the status code that is present in excel. which assertion can be used?

  • jakubiakjakubiak Posts: 384 admin

    If you want to validate the status code in the header, you can configure the "Valid HTTP Response Codes" field in the Success Criteria tab of your REST or Messaging Client. That field can be configured to pull from a data source.

  • divyangdivyang Posts: 8

    Thank you.

Sign In or Register to comment.