Search code examples
javascriptpostmannewman

Using "request" is deprecated. Use "pm.request" instead


I wanted to have the request name of my Postman collection in my newman report. So, I have added the following code to my script,

pm.test(`${request.name}: Status Assertion`, function () {
    pm.response.to.have.status(401);
});

I get the request name correctly. However, I'm getting the following warning in the console,

enter image description here

When I use pm.request,

console.log('Request name: ',pm.request.name)

I get the value as undefined, enter image description here

How do I get rid of the warning and have the name of the request?

Thanks in advance


Solution

  • This should be using pm.info.requestName here instead.

    https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#scripting-with-request-info

    You could also make use of the new pm.execution.location.current function here.

    https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#get-the-path-and-name-of-a-request