Is there a simple way to capture the Response times for the requests and responses in a PostMan script?
I am trying to do the following by creating a Collection and then in the Tests, writing the following script to capture and put the value in an Environment variable:
postman.setEnvironmentVariable("MyURLRequest", (responseTime));
This provides me the value in the Environment variable, but I need to specifically go there everytime to check the time.
The other way I have tried is to use the 'Runner' on the collection and get the response times from the "totalRequestTime" value in the exported results. But as I am running ~50 requests, it becomes hard to capture the same for each individual request.
Has anyone tried this earlier and been able to get a better way to capture and export a response time value for each request sent out?
You could use the built-in pm.response.responseTime
function to get the times.
Add it to a console.log(pm.response.responseTime)
in a test, to try it out or assign this to an env/global variable.
You could even (it's a little bit over kill though) do this:
If you didn't want it in each test, this could be added to the collection. On the latest version, press edit on the collection to see the options.
I could achieve this on Newman using below code:
"event": [
{
"listen": "test",
"script": {
"id": "aaaaaaaa-1111-4444-aaaa-000000011111",
"exec": [
"var rtm = pm.response.responseTime",
"var rts = rtm/1000",
"pm.test(\"Check response time and Status\", function () {",
"pm.response.to.have.status(200);",
"console.log(\"Response time in mili seconds\" , rtm);",
"console.log(\"Response time in seconds\" , rts);",
"});"
]
}
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With