1. What is Postman?
Postman is an API platform that is used to develop, share, test APIs. It is also used for creating documentation for APIs. Test suites can be quickly designed using Postman, and also it can store test information to be used in other tests.
It is integrated with Plugins, such as Jenkins's, which makes it more powerful.
2. What is a collection in Postman?
A collection is equivalent to a folder on your computer. It is a set of requests that are grouped together, preferably of the same type. It is one of Postman's most important features, and it also provides nice features such as running a whole group of request together with just one click.
3. What are all the environment variables in Postman?
A collection of key-value pairs is called an environment. Each name of the variable represents its keys. And referencing the name of the variable allows you to access its value.
It is a set of variables that differentiate among the requests. Such as, we can have an environment for testing, one for development and another for production. We can change the value of the variables to pass the data between requests and tests
4. What is payload in Postman?
The Payload of an API Module is the body of your request and response message. It contains the data that you send to the server when you make an API request. You can send and receive Payload in different formats, for instance JSON.
5. What is a Pre-request script in Postman?
Scripts in the Pre-request Script tab for a request, collection, or folder, you can carry out pre-processing such as setting variable values, parameters, headers, and body data
It will help for debugging code by logging the output in the console
6. Could you explain about Postman Variable scopes?
Postman resolves scopes according to a variable scope hierarchy. Using variables within specific scopes allows you to reuse values efficiently.
Postman supports the following variable scopes:
Global variables allow you to access data between collections, requests, test scripts, and environments. Global variables are available throughout a workspace.
Collection variables are available throughout the requests in a collection and are independent of environments, so do not change based on the selected environment.
Environment variables allow you to tailor your processing to different environments, for example local development vs testing or production. Only one environment can be active at a time.
Local variables are temporary, and only accessible in your request scripts. Local variable values are scoped to a single request or collection run, and are no longer available when the run is complete.
Data variables come from external CSV and JSON files to define data sets you can use when running collections via Newman or the Collection Runner.
7. What is the Postman execution order for a collection?
For every request in a collection, scripts will execute in the following order:
- A pre-request script associated with a collection will run prior to every request in the collection.
- A pre-request script associated with a folder will run prior to every request in the folder.
- A test script associated with a collection will run after every request in the collection.
- A test script associated with a folder will run after request in the folder.
8. What is the Postman execution order for a single request?
In Postman, the script execution order for a single request looks like this:
- A pre-request script associated with a request will execute before the request is sent
- A test script associated with a request will execute after the request is sent
9. How do you set a dynamic variable in Postman?
Postman uses the faker library to generate dummy data. You can generate random names, addresses, email addresses, and much more. You can use these pre-defined variables multiple times to return different values per request
You can use these variables like any other variable in Postman. Their values are generated at the time of execution and their names start with a $ symbol
e.g. $guid, $timestamp etc.
To use dynamic variables in pre-request or test scripts, you need to use pm.variables.replaceIn(),
10. How do you debug your collections, pre-request, test scripts in Postman?
We can debug written scripts by using Pre-request Script or Tests tabs, and we can validate log messages using the Postman console.
Postman console helps debug our requests when an API isn't behaving as we expect
Using the console: Below log statements at appropriate locations in our test scripts will help you identify the source of any issues. Every request sent by Postman is logged in the console, so you can view the detail of what happened when you sent a request.
open the console from the status bar on the bottom left of Postman or selecting View > Show Postman Console
Accessing console logs: Access the DevTools console logs, open the View menu and select Show DevTools. In the DevTools window, click Console to see the app debug logs.
Using the monitor console log: Refer left panel for monitor control, Create a monitor based on collection/environment and select the Console Log tab. This will display monitor run details, along with the console.log from pre-request and test scripts.
11. How do you use an assertion in the Postman?
Chai assertion library is available by default in the Postman. So when you are writing chai assertions, then don't worry about other processes of installation.
The main feature of Postman assertions is that they write the tests with English sentences, which is human readable. So it is very easy to read and user friendly.
Example Chai BDD expect assertion:
12. How to handle a self-signed certificate with Postman?
You can handle this by disabling SSL certificate verification in Postman. Settings->SSL certificate verification
13. What is pm object in postman?
The pm object provides most of the functionality for testing your request and response data, with the postman object providing some additional workflow control.
14. What is path and query parameter in Postman?
Request parameters are used to send additional information to the server. A request URL contains these parameters.
Path parameters form part of the request URL, which are referenced using placeholders preceded by ‘:’
Query parameters are appended to the end of the request URL, following ‘?’ and listed in key
value pairs, separated by ‘&’using the following syntax: ?id=1&type=new
15. What is request chaining in Postman?
Request chaining is process of sharing the data or variable value between the requests.
Let’s understand in details referring below,
- Create a request and send to the server
- Receive the response and copy a value from the response body or the header
- Store the value into environment variable using pm.environment.set("variable_key", "variable_value");
- Get the variable value to another request using pm.environment.get("variable_key");
- Again hit the send action and validate the response.
16. What is Newman and how it integrates with Postman?
Newman is a command-line Collection Runner for Postman. It enables you to run and test a Postman Collection directly from the command line.
The easiest way to install Newman is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.
$ npm install -g newman
Run the collection:
$ newman run mycollection.json
17. How do you generate a Postman HTML report?
Yes, we can generate good HTML report. In order to achieve this, we need to install another npm package i.e newman-reporter-htmlextra and add parameters to the newman execution command
Install using below command
$ npm install –g newman-reporter-htmlextra
Run below command to generate the report
$ newman run collection.json -r htmlextra --reporter-htmlextra-export ./results/report.html
18. What is JSON Schema and how to validate using Postman?
JSON Schema is a specification for defining the structure of JSON data i.e. JSON request body and response. JSON schema validation ensures that the JSON response format that we are getting is the same as the expected one.
- Send a request
- Generate a JSON schema using JSON schema generator tool
- Add the schema into Tests tab
- Validate using in-built JSON schema function
Assertion block with tests
19. How to validate xml response data using Postman?
we can use the library xml2Json that comes with Postman to convert XML to JSON so that you can extract the values from your XML response.
let responseJson = xml2Json(pm.response.text());
20. How will you upload an image with your request input?
Yes, we can upload an image in the body of the POST Method.
Refer below steps,
- select Body -> form-data -> Enter your parameter name (image file name) and on right side next to value column, there will be dropdown "text, file",
- select File. choose your image file and post it.