0

I have an api definition like this :

{
"myVar01": "{{myVar01}}",
"myVar02": "{{myVar02}}",
"myVar03": "{{<myVar03>}}",
"myVar04": {
    "myVar04-01": "{{myVar04-01}}",
    "myVar04-02": "{{myVar04-02}}",
    "myDataArray": [
        {
            "myArrayVar01": "{{myArrayVar01}}",
            "myArrayVar02": "{{myArrayVar02}}",
            "myArrayVar03": "{{myArrayVar03}}",
            "myArrayVar04": "{{myArrayVar04}}",
            "myArrayVar05": "{{myArrayVar05}}"
        },
        {
            "myArrayVar01": "{{myArrayVar01}}",
            "myArrayVar02": "{{myArrayVar02}}",
            "myArrayVar03": "{{myArrayVar03}}",
            "myArrayVar04": "{{myArrayVar04}}",
            "myArrayVar05": "{{myArrayVar05}}"
        },
        .....
    ]
    ]
}

}

I have to create a data file to run several tests on this api, the question is how can I define my data file to create data for "myDataArray" structure?

user2776069
  • 109
  • 1
  • 2
  • 10
  • Create csv file with variable names and values. Refer this answer: https://stackoverflow.com/a/55058791/4753489 – Divyang Desai Jan 09 '20 at 13:23
  • Thanks but it is not the question I asked, I already have the CSV file, in fact not CSV, I use JSON file because I wans't able to get variables from the CSV file and it woks like a charm with the JSON one, but never mind. The question is about creating into the file a kindof array to handle multiple value for myDataArray per test group – user2776069 Jan 09 '20 at 15:36

1 Answers1

0

Ok, finally I found the problem.

The API definition has to be like this :

    {
    "myVar01": "{{myVar01}}",
    "myVar02": "{{myVar02}}",
    "myVar03": "{{myVar03}}",
    "Struct": {
        "myVar04-01": "{{myVar04-01}}",
        "myVar04-02": "{{myVar04-02}}",
        "myDataArray": {{localVarDataAray}}
    }
}

The json file has to be like that :

    [
{
  "myVar01": "0123456789012345678901234567890123456789",
  "myVar02": "0123456789012345678901234567890123456789",
  "myVar03": "0123456789012345678901234567890123456789",
  "myVar04-01": "0123456789012345678901234567890123456789",
  "myVar04-02": "0123456789012345678901234567890123456789",
  "myDataArray":[{
                "myArrayVar01": 1,
                "myArrayVar02": 1,
                "myArrayVar03": 1,
                "myArrayVar04": 4,
                "myArrayVar05": 0
            },{
                "myArrayVar01": 2,
                "myArrayVar02": 2,
                "myArrayVar03": 2,
                "myArrayVar04": 4,
                "myArrayVar05": 0
            }]
},
{
  "myVar01": "0123456789012345678901234567890123456789",
  "myVar02": "0123456789012345678901234567890123456789",
  "myVar03": "0123456789012345678901234567890123456789",
  "myVar04-01": "0123456789012345678901234567890123456789",
  "myVar04-02": "0123456789012345678901234567890123456789",
  "myDataArray":[{
                "myArrayVar01": 1,
                "myArrayVar02": 1,
                "myArrayVar03": 1,
                "myArrayVar04": 4,
                "myArrayVar05": 0
            },{
                "myArrayVar01": 2,
                "myArrayVar02": 2,
                "myArrayVar03": 2,
                "myArrayVar04": 4,
                "myArrayVar05": 0
            }]
}
]

And I had to define a pre-request sctipt like that :

 let localVarDataAray="";
pm.variables.set('localVarDataAray',JSON.stringify(data.myDataArray));

And it works fine

user2776069
  • 109
  • 1
  • 2
  • 10