How to validate existance of a file using postman script?

I am testing a API which returns response and for authenticated user along with that also download a file in local. I want to validate that whether the file is downloaded. I have tried
with Postman script using new File("/data/file/abc.json") and new ActiveXObject(“Scripting.FileSystemObject”) but not able to do it.

var testFile= new File("/data/file/abc.json");

if(TestFile.exists()){
console.log(‘The file exists’);
}else{
console.log(‘The file does not exist’);
}

I am getting error ReferenceError: File is not defined

Postman doesn’t provide entire Node modules for scripts

For security purposes, Postman uses a sandbox script execution environment

Modules available within this Sandbox are listed here

For the usecase you are trying to solve
You should get the file’s content as part of the API response when invoking the API via Postman.

You may then look for Content-Disposition header within the test script

Example Header:

Content-Disposition: attachment; filename="somename.json"

For your reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

By checking the header value you can see what the filename is.
And if you want to check the file’s content it should be part of the response body.

Example Postman test script:

pm.test("Content-Disposition is set", function () {
    pm.response.to.have.header("Content-Disposition", "attachment; filename=\"somename.json\"");
});
3 Likes

Thanks Amit for your reply. I am new to Postman and started using it just few days back.
Let me try and I’ll come back to you if need more information on this. :slightly_smiling_face: