Search code examples
jsonrestjmeterweb-api-testing

How to use csv to provide different values for json assertion for different inputs in Jmeter?


I am relatively new to API Testing.

Currently I have a setup where I am having different request jsons and for each request json there is different repsonse json assertion configuration provided with the appropriate values in Jmeter.

Since my json structure will be same and only the input values will be different, I am thinking to generalize the input values using csv and keep only one request configuration.

But would I be able to provide different values(like jsonpath and expected value) to one response json assertion configuration using csv? Because the jsonpath and expected value both will depend upon the input provided and it can have major difference as per the case.

If yes, then how to do it please let me know.

Also if I can achieve my use case using other free API Testing Tool like Postman then also let me know.


Solution

  • You can normally parameterize any JMeter Test Element using CSV Data Set Config

    1. For example you have the following response:

      { "name":"John" }
      
    2. And the following CSV file:

      $.name,John
      $.name,Jane
      
    3. Add CSV Data Set Config to your Test Plan and configure it like:

      enter image description here

    4. Add JSON Assertion as a child of the request which returns the above JSON and configure it like:

      enter image description here

    5. That's it, each virtual user and/or iteration will pick up the next line from the CSV file and the ${jsonPath} and ${name} placeholders will be replaced with their respective values:

      enter image description here

      as you can see, the first request passed because name matched John and the second failed because the assertion expected name to be Jane and got John