'Calling a Variable from a JSON File for use in Postman Tests
My test URL looks like this:
{{baseURL}}/api/v1/{{testName}}
When I run this test in the runner, it does not pull in the testName variable.
My json data file looks like this:
[
{
"testName": "12345"
{
"test1": "1234",
"test2": "2468"
},
{
"test1": "1357",
"test2": "9876"
},
"testName": "2468"
{
"test1": "1234",
"test2": "2468"
},
{
"test1": "1357",
"test2": "9876"
}
}
]
But this doesn't work.
So I am trying to call the variable from the .json file in the runner, then proceed to check the expected data against the actual data from the request. Then when finished the one test, will then proceed to the next test.
Solution 1:[1]
The structure of the datafile would be like this simple example:
[
{
"testName": "12345"
},
{
"testName": "2468"
}
]
When used in the Collection Runner, the {{testName}} variable in the URL, would be resolved to the value in the object.
Each of the objects in the array, within the JSON file, is an iteration. So for the first run, it would pick up 12345 and in the second run it would pick up 2468.
If you would need to check the expected data in the file in an iteration, the structure would need to look like this:
[
{
"testName": "12345",
"test1": "1234",
"test2": "2468"
},
{
"testName": "2468",
"test1": "0987",
"test2": "4567"
}
]
I'm not aware of your full use case here so this is just an example.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Danny Dainton |
