Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response times from PostMan scripts

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?

like image 728
gagneet Avatar asked Dec 07 '17 05:12

gagneet


2 Answers

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:

Response Times

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.

like image 189
Danny Dainton Avatar answered Sep 19 '22 13:09

Danny Dainton


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);",
                   "});"    
                ]
            }
     }
]
like image 43
eaccmk Avatar answered Sep 20 '22 13:09

eaccmk