1.

How can we use Custom Javascript libraries in our scripts with an example?

Answer»

Postman provides a lot of built-in tools and libraries that we can USE to add in our pre-request or POST-request scripts or test CASES. Let us take the example of using the moment.js library. It provides a lot of useful functions to format data around time. Consider that we have a POST request that needs to specify the created date to the user which expects the format “DD/MM/YYYY”. We can use the moment library to perform this using a single line of code. In our pre-request script, we need to add the below lines of code to get the correctly formatted data and then store that in an environment variable:

var moment = require('moment');pm.environment.set('createdDate',moment().format('DD/MM/YYYY'));

There are a lot of other useful libraries LIKE crypto.js that are useful for converting text to encrypted values which can further be used ANYWHERE in the request body.



Discussion

No Comment Found