Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

JSON assertion validation for status code 200.

divyang
divyang 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

  • divyang
    divyang Posts: 8

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

    200.png 29.6K
  • jakubiak
    jakubiak Posts: 795 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.

  • divyang
    divyang 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?

  • jakubiak
    jakubiak Posts: 795 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.

  • divyang
    divyang Posts: 8

    Thank you.