Hey there, I would love to create a simple check that compares that the city name of the API matches the city name from the file.
URL
GET - api.openweathermap.org/data/2.5/weather?q={{$setCityName}}&appid=304656eaa6952374cdd57a2b6100659b
pre-request Script:
pm.test("Set city name", function () {
var setCityName = pm.iterationData.get("name");
});
Tests:
pm.test("Response has set correct data value", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.name).to.equal(pm.iterationData.get("name"));
});
You can tell because it is highlighted in red in the request url, but you can also see in the console at the bottom that the variable isn’t resolving.
yeah I noticed that, thank you for letting me know, would you be so nice and try to let me know how can I set the variable to be the value of the JSON file in the “name”?
I guess there are at least two steps:
attaching the file probably in the Body > form-data tab
setting the variable setCityName to that file… probably by var setCityName = pm.iterationData.get(“name”); or sth like that…
Thank you very much for your response!
All I need to do is to set variable to load from external file
If you’re just using it in the url like that, you don’t need to do anything special. Just change the variable in the url to {{name}} since that is how it’s defined in your json data
It’s still unsure what it is you’re trying to do.
The test in the pre-request isn’t really doing anything and the code within it doesn’t need to be there. It will work outside of that test function.
Does that endpoint expect a file in a GET request? Not sure what’s happening there.
You’re still using iterationData in the tests but that won’t do anything unless you’re using the Collection Runner and you’re using a datafile on the Collection Run.