We have already seen usage of Query params in API. We may need to retrieve query parameters value in Tests and Pre-request Script for validation. So in this post, we will see how can we retrieve query parameters value.
To get value of specific query parameter:-
pm.request.url.query.get(<Parameter name>)
To get all query parameter as a list:-
pm.request.url.query.all()
To get query string of URI:-
pm.request.url.getQueryString()
Let’s see above concept in an example:-
Let’s add params to API:-
Add script to Tests:-
Hit and see Postman Console:-
Import above example from below collection:-
https://www.getpostman.com/collections/531abaa3ed7ce38c9d9b
Refer basics of API Testing here.
Refer detailed tutorial of Postman here.
More about API Testing in upcoming posts. Stay tuned.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyApiTesting
Great post Amod. I was able to utilize your code examples and make this work. However, I tried running a test from the Collection Runner, that reads a .csv file that has the data, and in those instances, it’s returning just the query param variable name {{queryParam}} nor the value. Do you have a suggestion on how this may work in the instance of running a test using the Collection Runner and csv file with query parameters?