Hi, I am a complete noob to this stuff so I apologize ahead of time. I am using Postman version: 7.2.0
- Let’s say I have a collection and I have a POST and a GET. One to post a username and location, and one to get all users. I want the username to be unique.
POST payload just takes
user: “username”,
location: “location”
So, I edit collections and put in variable “username” with value user{$timestamp}.
In the body of my request, do I simply do:
username: “{username}”,
location: “location123”
It seems like it’s not working. I have tried without quotes and with quotes. Any ideas what I might be doing wrong?
- Let’s say I get the above to work. Now, in my GET usernames, I’d like to search for that specific user that was a dynamic value.
Would it be correct in using the “test” tab of the POST request and do something like:
pm.globals.set(“usernameToSearch”, pm.variables.get({{username}}));
Now would I be able to do the GET request and in its “test” tab put in an assertion like:
pm.test(“username is in response”, function () {
pm.expect(pm.response.text()).to.include(postman.getGlobalVariable(“usernameToSearch”));
});
- What happens when I start the runner and want to run this using that and a data file instead?
If I wanted to test 3 usernames, how would I do this? Everything remains the same and just create a csv to upload?
Would the CSV be:
username,location
username{$timestamp},location123
username{$timestamp},location456
username{$timestamp},location789
- What if I want to assert for the username and location.
Would it be:
pm.test(“username is in response”, function () {
pm.expect(pm.response.text()).to.include(data.username);
});
pm.test(“username is in response”, function () {
pm.expect(pm.response.text()).to.include(data.location));
});
- If that is correct, now that I leave the runner and run the steps manually, would the assertion still work? Is it looking at the data file still? Or is it now looking at the variables that I had set in the collection?
If the latter, does that mean I have to fix the assertion? I would have to keep doing this every time I switch from using runner vs manually sending a request?
Thank you for reading.