This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How do you get the cURL command based on the details of REST API obtained from Postman? |
|
Answer» We can obtain the cURL command equivalent by following the below steps:
Postman has become the most popular and beloved tool for API testing. Hence, hands-on EXPERIENCE with the Postman tool has become very important for any BACKEND developer. Recommended Resources: API Testing REST API Software Testing Web Services |
|
| 2. |
What do you understand by Scratch Pad? |
|
Answer» Scratch Pad is a space provided by Postman that helps us to work without being connected to Postman servers. It provides the flexibility of utilizing some of the features of postman offline. The features include- COLLECTION creation, creating requests and the ability to send requests. These are stored LOCALLY and once LOGGED in, the work is SAVED into the workspace. |
|
| 3. |
How will you generate random numbers of a given range in Postman? |
|
Answer» Suppose you want to generate numbers between the range 1 to N, then it can be DONE in the pre-request script as FOLLOWS: pm.globals.set('randomNumber', Math.floor(Math.random() * N));We can then use this VARIABLE in the URL as:{{randomNumber}} |
|
| 4. |
Does Postman allow flexibility to make use of the command-line? |
|
Answer» Postman provides a command-line tool CALLED Newman using which we can run any Postman collection. It is a NodeJS based package that requires a node environment for executing collections using Newman Collection Runner. It has full parity with Postman’s Collection Runner i.E it provides support for RUNNING assertions, pre-request scripts, or other request scripts LINKED with the REQUESTS that belong to the collection. We can use Newman by following the below steps:
|
|
| 5. |
If we have a global and a local variable of the same name, which one will be given the most preference in Postman? |
|
Answer» In such cases, the HIGHER PRECEDENCE is given to the LOCAL variable by OVERWRITING the value of the global variable. |
|
| 6. |
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. |
|
| 7. |
What do you understand by the pre-request script? |
|
Answer» Pre-REQUEST scripts are those scripts that are used for executing Javascript code before a request is run. It is used for performing pre-processing tasks like setting variables, PARAMETERS, HEADERS, body DATA, etc. |
|
| 8. |
How will you stop the execution of upcoming requests or execution of the collections? |
|
Answer» We can use the below code to stop the EXECUTION of the next REQUEST: pm.setNextRequest(NULL); |
|
| 9. |
Does Postman provide a feature to log requests and responses? |
|
Answer» Postman does allow VIEWING of requests and response parameters in the software application itself. But it is important to see how the request was sent upon applying the pre-request scripts. In such cases, Postman has an additional tool called “Postman Console” which is used for viewing EVERY request and response DETAIL. We can also log the DETAILS in the console by USING console.log statements in the scripts. |
|
| 10. |
What are workspaces in Postman? What are their uses? |
|
Answer» Workspaces are the areas/space given by Postman for team collaboration to work on a specific or SET of collections. It provides a way to logically separate requests or collections that are personal to the developer or the team so that the maintenance of requests is made easy. There are two types of workspaces in Postman:
We can create a new workspace by clicking on the Workspace icon and then clicking on “Create New”. We can select our workspace to be personal or team workspace by configuring the properties in the create window. |
|
| 11. |
How do you set the same headers for all requests in a Postman Collection? |
|
Answer» Postman COLLECTIONS allow using pre-request scripts at the individual request level and the collection level. We can add any SCRIPT that applies to all requests in the collection in the pre-request scripts. We can do it by following the below steps:
Header from Pre-Request Script: |
|
| 12. |
How do you write test cases for basic authentication in Postman? |
|
Answer» Basic Authentication is one of the authentication techniques provided in Postman that ENSURES that we can set the username and password along with the API requests. We can do this by first setting the CREDENTIALS of the API by:
The test CASES can be WRITTEN as follows: pm.test("Is the Request Authenticated?", FUNCTION () { var jsonData = pm.response.json(); //if authenticated then assert to true pm.expect(jsonData.authenticated).to.eql(true); }); pm.test("Is the Content-Type present?", function () { pm.response.to.have.header("Content-Type"); }); pm.test("Is it a successful POST Request?", function () { pm.response.to.have.status(200); }); |
|
| 13. |
Is it possible to reuse the authentication token for multiple requests? |
|
Answer» YES, it is POSSIBLE. It can be achieved by creating a collection and adding all the requests having the same authentication token to that collection and then assigning the AUTH token to the collection. This can be applied to the INDIVIDUAL requests by selecting the “Inherit auth from PARENT” option in the Authorization tab. |
|
| 14. |
What are the various variable scopes provided by Postman? |
|
Answer» Postman has the following VARIABLE scopes:
|
|
| 15. |
Is it preferable to save our work on Postman Cloud? |
|
Answer» When working on enterprise-level applications for organizations, it is not PREFERRED to STORE our WORK on the POSTMAN cloud because of the required privacy and security. In the Postman cloud, there are chances of security BREACHES by a skilled hacker. |
|
| 16. |
What is the purpose of the 304 status code? |
|
Answer» 304 status code STANDS for NOT MODIFIED. This is used for diminishing the bandwidth of the network in cases of restricted GET requests. In such cases, the RESPONSE BODY should be empty or blank and the headers should have a date, LOCATION, signature ETC. |
|
| 17. |
Why is Base64 encoding primarily used in Postman? |
|
Answer» Base64 encoding is primarily USED because it does the task of data TRANSMISSION in a textual format that is easier to be sent in the requests in HTML form statistics format. Another reason why we USE this is that using identical 64 characters for encoding is heavily reliable in any language we use. |
|