How to maintain json data for multiple testcases in robotframework

Viewed 187

please suggest me how to maintain json POST data(for API testing) for multiple test cases in robotframework based on your past experience. Whether to maintain it in excel and separate json files?

2 Answers
  1. If you have a "template" JSON and need to parameterize individual values you can use CSV Data Set Config for supplying these values, you request would be something like:

    {
      "parameter1": "${value1}",
      "parameter2": "${value2}"
    }
    

    where these ${value1} and ${value2} will be populated from CSV data set config

  2. If you need to send totally different JSON with each request it will make sense to put all the payload files into some folder and then:

It's better to store POST data as separate JSON file. Here is how I would store:

- testdata
  - json
    - sample_file1.json
    - sample_file2.json

There is advanced option if you don't like to store pre-defined JSON file for each test case but rather to generate one. You can use JSON Schema to generate JSON files, all you have to do is to create schema and generate JSON files based on that schema.

Related