100% found this document useful (1 vote)
1K views40 pages

Postman - Guru99

Postman is a widely used API testing tool that allows users to organize API calls into collections and test suites. It provides features like parameterization of requests, test automation, and integration with continuous integration pipelines. The document provides instructions on downloading and installing Postman, making API requests using both GET and POST methods, parameterizing requests using variables, and creating test suites.

Uploaded by

gayu89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views40 pages

Postman - Guru99

Postman is a widely used API testing tool that allows users to organize API calls into collections and test suites. It provides features like parameterization of requests, test automation, and integration with continuous integration pipelines. The document provides instructions on downloading and installing Postman, making API requests using both GET and POST methods, parameterizing requests using variables, and creating test suites.

Uploaded by

gayu89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

What is Postman?

Postman is a scalable API testing tool that quickly integrates into CI/CD
pipeline. It started in 2012 as a side project by Abhinav Asthana to simplify
API workflow in testing and development. API stands for Application
Programming Interface which allows software applications to communicate
with each other via API calls.

In this Postman tutorial, you will learn:

● What is Postman?
● Why Use Postman?
● How to Download and Install POSTMAN
● How to use Postman to execute APIs
● Working with GET Requests
● Working with POST Requests
● How to Parameterize Requests
● How to Create Postman Tests
● How to Create Collections
● How to Run Collections using Collection Runner
● How to Run Collections using Newman

Why Use Postman?


With over 4 million users nowadays, Postman Software has become a tool of
choice for the following reasons:
1. Accessibility – To use Postman tool, one would just need to log-in to
their own accounts making it easy to access files anytime, anywhere as
long as a Postman application is installed on the computer.
2. Use of Collections – Postman lets users create collections for their
Postman API calls. Each collection can create subfolders and multiple
requests. This helps in organizing your test suites.
3. Collaboration – Collections and environments can be imported or
exported making it easy to share files. A direct link can also be used to
share collections.
4. Creating Environments – Having multiple environments aids in less
repetition of tests as one can use the same collection but for a different
environment. This is where parameterization will take place which we
will discuss in further lessons.
5. Creation of Tests – Test checkpoints such as verifying for successful
HTTP response status can be added to each Postman API calls which
help ensure test coverage.
6. Automation Testing – Through the use of the Collection Runner or
Newman, tests can be run in multiple iterations saving time for repetitive
tests.
7. Debugging – Postman console helps to check what data has been
retrieved making it easy to debug tests.
8. Continuous Integration – With its ability to support continuous
integration, development practices are maintained.

How to Download and Install POSTMAN


Being an Open Source tool, Postman can be easily downloaded. Here are the
steps to install:
Step 1) Download Postman
Go to https://www.postman.com/downloads/ and choose your desired platform
among Mac, Windows or Linux. Click Download.
Step 2) Click on Run
Your download is in progress message should now display on the Apps page.
Once the Postman download is completed, click on Run.

Step 3) Postman Installation Start


Wait for some time to Complete the Installation of Postman.
Step 4) Signup for Postman Account
In the next window, Signup for a Postman Account

NOTE: There are two ways to sign up for a Postman account. One is to create
an own Postman account, and the other is to use a Google account. Though
Postman allows users to use the tool without logging in, signing up ensures
that your collection is saved and can be accessed for later use.

Step 5) Click on Save My Preferences


Select the workspace tools you need and click Save My Preferences

Step 6) Congratulation!
You will see the Startup Screen
How to use Postman to execute APIs
Below is the Postman Workspace. Let’s explore the step by step process on
How to use Postman and different features of the Postman tool!

1. New – This is where you will create a new request, collection or


environment.
2. Import – This is used to import a collection or environment. There are
options such as import from file, folder, link or paste raw text.
3. Runner – Automation tests can be executed through the Collection
Runner. This will be discussed further in the next lesson.
4. Open New – Open a new tab, Postman Window or Runner Window by
clicking this button.
5. My Workspace – You can create a new workspace individually or as a
team.
6. Invite – Collaborate on a workspace by inviting team members.
7. History – Past requests that you have sent will be displayed in History.
This makes it easy to track actions that you have done.
8. Collections – Organize your test suite by creating collections. Each
collection may have subfolders and multiple requests. A request or
folder can also be duplicated as well.
9. Request tab – This displays the title of the request you are working on.
By default, “Untitled Request” would be displayed for requests without
titles.
10. HTTP Request – Clicking this would display a dropdown list of
different requests such as GET, POST, COPY, DELETE, etc. In
Postman API testing, the most commonly used requests are GET and
POST.
11.Request URL – Also known as an endpoint, this is where you will
identify the link to where the API will communicate with.
12. Save – If there are changes to a request, clicking save is a must so
that new changes will not be lost or overwritten.
13. Params – This is where you will write parameters needed for a
request such as key values.
14. Authorization – In order to access APIs, proper authorization is
needed. It may be in the form of a username and password, bearer
token, etc.
15. Headers – You can set headers such as content type JSON
depending on the needs of the organization.
16. Body – This is where one can customize details in a request
commonly used in POST request.
17. Pre-request Script – These are scripts that will be executed before
the request. Usually, pre-request scripts for the setting environment are
used to ensure that tests will be run in the correct environment.
18. Tests – These are scripts executed during the request. It is important
to have tests as it sets up checkpoints to verify if response status is ok,
retrieved data is as expected and other tests.
Working with GET Requests
Get requests are used to retrieve information from the given URL. There will
be no changes done to the endpoint.
We will use the following URL for all examples in this Postman tutorial
https://jsonplaceholder.typicode.com/users

In the workspace
1. Set your HTTP request to GET.
2. In the request URL field, input link
3. Click Send
4. You will see 200 OK Message
5. There should be 10 user results in the body which indicates that your
test has run successfully.
*Note: There may be cases that Get Postman request may be unsuccessful.
It can be due to an invalid request URL or authentication is needed.

Working with POST Requests


Post requests are different from Get request as there is data manipulation with
the user adding data to the endpoint. Using the same data from the previous
tutorial in Get request, let’s now add our own user.
Step 1) Click a new tab to create a new request.

Step 2) In the new tab


1. Set your HTTP request to POST.
2. Input the same link in request url:
https://jsonplaceholder.typicode.com/users
3. switch to the Body tab

Step 3) In Body,
1. Click raw
2. Select JSON

Step 4) Copy and paste just one user result from the previous get request like
below. Ensure that the code has been copied correctly with paired curly
braces and brackets. Change id to 11 and name to any desired name. You
can also change other details like the address.
[
{
"id": 11,
"name": "Krishna Rungta",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered
client-server neural-net",
"bs": "harness real-time e-markets"
}
}
]

*Note: Online Post request should have the correct format to ensure that
requested data will be created. It is a good practice to use Get first to check
the JSON format of the request. You can use tools like
https://jsonformatter.curiousconcept.com/
Step 5) Next,
1. Click Send.
2. Status: 201 Created should be displayed
3. Posted data are showing up in the body.

How to Parameterize Requests


Data Parameterization is one of the most useful features of Postman. Instead
of creating the same requests with different data, you can use variables with
parameters. These data can be from a data file or an environment variable.
Parameterization helps to avoid repetition of the same tests and iterations can
be used for automation testing.
Parameters are created through the use of double curly brackets: {{sample}}.
Let’s take a look at an example of using parameters in our previous request:

Now let’s create a parameterize get request.


Step 1)
1. Set your HTTP request to GET
2. Input this link: https://jsonplaceholder.typicode.com/users. Replace the
first part of the link with a parameter such as {{url}}. Request url should
now be {{url}}/users.
3. Click send.
There should be no response since we have not set the source of our
parameter.

Step 2) To use the parameter you need to set the environment


1. Click the eye icon
2. Click edit to set the variable to a global environment which can be used
in all collections.

Step 3) In variable,
1. set the name to the url which is https://jsonplaceholder.typicode.com
2. click Save.
Step 4) Click close if you see the next screen
Step 5) Go back to your Get request then click send. There should now be
results for your request.
*Note: Always ensure that your parameters have a source such as an
environment variable or data file to avoid errors.

How to Create Postman Tests


Postman Tests are JavaScript codes added to requests that help you verify
results such as successful or failed status, comparison of expected results,
etc. It usually starts with pm.test. It can be compared to asserts, verify
commands available in other tools.
Let’s do some basic API testing using Postman for our parameterize requests
from the previous lesson.
Step 1) Go to your GET user request from the previous tutorial.
1. Switch to the tests tab. On the right side are snippet codes.
2. From the snippets section, click on “Status code: Code is 200”.
The pane is auto-populated
Step 2) Now click Send. The test result should now be displayed.

Step 3) Go back to the test tab and let’s add another test. This time we will
compare the expected result to the actual result.
From the snippets section, click on “Response body:JSON value check”. We
will be checking if Leanne Graham has the userid 1.
Step 4)
1. Replace “Your Test Name” from the code with “Check if user with id1 is
Leanne Graham” so that the test name specifies exactly what we want
to test.
2. Replace jsonData.value with jsonData[0].name. To get the path, check
the body in Get result earlier. Since Leanne Graham is userid 1,
jsonData is in the first result which should start with 0. If you want to get
the second result, use jsonData[1] and so on for succeeding results.
3. In to eql, input “Leanne Graham”
pm.test("Check if user with id1 is Leanne Graham",
function () {
var jsonData = pm.response.json();
pm.expect(jsonData[0].name).to.eql("Leanne
Graham");
});
Step 5) Click send. There should now be two passed test results for your
request.

*Note: There are different kind of tests that can be created in Postman. Try to
explore the tool and see what tests will fit your needs.

How to Create Collections


Collections play an important role in organizing test suites. It can be imported
and exported making it easy to share collections amongst the team. In this
tutorial, we will learn how to create and execute a collection.
Let’s start in creating a collection:
Step 1) Click on the New button at the top left corner of the page.

Step 2) Select Collection. Create collection window should pop up.


Step 3) Input the desired collection name and description then click create. A
collection should now be created.
Step 4) Go back to the previous Get request. Click Save

Step 5)
1. Select Postman Test Collection.
2. Click Save to Postman Test Collection
Step 6) Postman test collection should now contain one request.
Step 7) Repeat steps 4-5 for the previous Post request so that collection will
now have two requests.
How to Run Collections using Collection Runner
There are two ways to run a collection which is the Collection Runner and
Newman. Let’s begin by executing the collection in Collection Runner.
Step 1) Click on the Runner button found at the top of the page next to the
Import button.

Step 2) Collection Runner page should appear such as below. Following is


the description of various fields
Step 3) Run your Postman Test Collection by setting up the following:
● Choose Postman test collection- Set iterations as 3
● Set delay as 2500 ms
● Click on Run Postman Test… button
Step 4) Run Results page should be displayed after clicking the Run button.
Depending on the delay, you should see the tests as they execute.
1. Once tests have finished, you can see the test status if it is Passed or
Failed and the results per iteration.
2. You see Pass status for the Get Requests
3. Since we did not have any tests for Post, there should be a message
that the request did not have any tests.
You can see how important it is that there are tests in your requests so that
you can verify HTTP request status if successful and the data is created or
retrieved.

How to Run Collections using Newman


Another way to run a collection is via Newman. The main differences between
Newman and Collection Runner are the following:
1. Newman is an add-on for Postman. You will need to install it separately
from the Native App.
2. Newman uses the command line while Collection Runner has a GUI.
3. Newman can be used for continuous integration.
To install Newman and run our collection from it, do the following:
Step 1) Install nodejs using this link: http://nodejs.org/download/
Step 2) Open the command line and enter
npm install -g newman
Newman should now be installed on your computer.
Step 3) Once Newman has been installed, let’s go back to our Postman
workspace.In the Collections box, click on the three dots. Options should now
appear. Select Export.
Step 4) Choose Export Collection as Collection v2.1 (Recommended) then
click Export.
Step 5) Select your desired location then click Save. It is advisable to create a
specific folder for your Postman tests. A collection should now be exported to
your chosen local directory.
Step 6) We will also need to export our environment. Click on the eye icon
beside the environment dropdown in Global, select Download as JSON.
Select your desired location then click Save. It is advisable that the
environment should be in the same folder as your collection.
Step 7) Environment should now be exported to the same local directory as
Collection.
Step 8) Now go back to command line and change the directory to where you
have saved the collection and environment.
cd C:\Users\Asus\Desktop\Postman Tutorial
Step 9) Run your collection using this command:
newman run
PostmanTestCollection.postman_collection.json -e
Testing.postman_globals.json
Run results should now appear such as below.
For guide is a reference to some basic Newman codes for execution:
1. Run a collection only. This can be used if there is no environment or
test data file dependency.
2. newman run <collection name>Run a collection and
environment. The -e indicator is for environment.
3. newman run <collection name> -e <environment name>Run
a collection with desired no. of iterations.
4. newman run <collection name> -n <no.of iterations>Run
with data file.
5. newman run <collection name> --data <file name> -n
<no.of iterations> -e <environment name>Set delay time.
This is important as tests may fail if it is run without delay due to
requests being started without the previous request completing
processing on the endpoint server.
newman run <collection name> -d <delay time>
Our Postman interview questions guide will help you crack the interview and
help you get your dream job for software testing.

Summary
● API Testing using Postman: Postman is an application for testing APIs.
Postman is one of the most popular tools used in API testing by sending
requests to the webserver and getting the response back
● Accessibility, Use of Collections, Collaboration, Continuous Integration,
are some of the Key features to learn in Postman
● It’s recommended you create an account in Postman, so your
collections are available online
● You can parameterize request in Postman
● You can create Tests to verify a postman request
● Collections can be run using Newman or Collection Runner

Top 47 Postman Interview Questions and


Answers (2022)

The Postman is a popular API testing tool that helps the development team
create, share, and test documents of API. The Postman tool provides a GUI
interface to test an API and a command-line utility for experienced testers.
This API testing tool also helps you to create the request as per the need of
API. The Postman team has also released a Chrome extension that can be
used to test the API from your browser.
The list below covers all the Postman questions for freshers and
professional-level candidates. This Postman interview questions guide will
help you crack the interview and help you get your dream job for software
testing.
1) What is Postman?
The Postman is a highly popular API testing tool that helps the development
team create, share, and test an API. The Postman tool provides a GUI
interface to the API and a command-line utility for experienced testers.
2) What is an HTTP request?
An HTTP request is a program that the client makes to a name host located
on a server. It works as a communication interface or a request-response
protocol between a client and server. The primary use of the HTTP request is
to access a resource on the server. To initiate the HTTP request, the client
uses components of a URL (Uniform Resource Locator) that also includes the
information needed to access the resource.
3) State The Core Components of an HTTP Response?
In Postman, every HTTP response contains four key elements.
● Response/Status Code- There are response code issues by a sever
for client’s request, as 404 means Page Found.
● HTTP Version- HTTP version name. For example, HTTP v2.2
● Response Header- It included information for the HTTP response
message. For example. The content length, date, status, server type,
etc.
● Response Body – It contains the data which a client requested from
the server.
4) Why do we use Postman?
Here are some most prominent reasons for using Postman:
● It is free to use software which is helpful for API testing
● It helps you to manage the end-to-end lifecycle of API
● It offers Runtime Service that helps manage API collections,
workspaces, environments, and different examples.
● You can also integrate Postman with CI/CD tools like Circle CI, Jenkins,
etc.
● It has a vast community forum that can easily address any technical
issues you face while using the tool.
5) What is API?
Application Programming Interface (API) is a software interface that enables
two applications to interact with each other without any user intervention. It is
a collection of software functions and procedures. API is defined as a code
that helps two different software communicate and exchange data with each
other.
6) What are the important authorization methods supported by
Postman?
Postman offers the following API request authorization options 1) API Key, 2)
Oauth 1.0 and 2.0, 3) Basic auth, 4) Digest auth, 5) Bearer Token, 6) AWS
Signature, 7) Hawk Authentication, 8) NTLM Authentication.
7) How do you log variable values in Postman?
Postman allows to log the variable values in Postman in the console by using
the following command:

console.log(pm.variables.get("guru99"));

8) Postman is available as a native desktop app for?


Postman API testing tool is currently available for Mac, Windows (32-bit /
64-bit), and Linux (32-bit / 64-bit)
9) What is the History tab in Postman?
All the request you send in Postman appears under the History tab of the
sidebar. It is very much similar to browser history, which you can clear
whenever you want.
10) What is Basic Auth in Postman?
In Postman, Basic Auth is an authorization method provided for HTTP user
agents like web browsers to enter username and password. After entering the
username and password that you can associate with the request.
11) What is a binary form in POST methods?
Post binary firm is designed to send the information in a format that is
impossible to enter manually. These options are used while sending larger
files like CSV files, etc.
12) What is the main difference between Authorization and
authentication?
Here are a few differences between authorization and Authentication:
● Authorization is the act of allowing or permitting someone, whereas
authentication is proving that something is genuine.
● Authorization always comes first, while authentication comes after
authorization.
● Authorization is open to anyone with permission, whereas
authentication requires you to have a password.
13) What is the Payload in Postman?
The Payload of an API Module is the body of your request and response
message. When making an API request, it contains the data you send to the
server. You can send and receive Payload in various formats, for example,
JSON or XML.
14) What is a collection in Postman?
A collection in Postman enables you to group similar requests. It also allows
you to systematically arrange the requests into folders.
15) What is a Pre-Request script?
Pre-request scripts help you to execute JavaScript before a request runs. It
allows you to accomplish pre-processing tasks like setting variable values,
parameters, headers, and body data.
16) How the Postman variables are accessed?
The Postman variables are always accessed by using the variable name:

{{variable name}}

17) What is the meaning of the term environment in Postman?


The environment in Postman is a set of key-value pairs. Postman allows you
to build multiple environments and switch among them with a click of a button.
18) Why does Postman never accepts any other encoding apart from
Base64?
You can use base64 as it helps us transmit the data into the textual form and
send it as HTML form data. Moreover, we must rely upon the same 64
characters in any encoding language.
19) Which kind of encoding does Postman accepts for authorization
credentials?
Postman only accepts Base64 encoding, which is provided inbuilt in Postman.
Otherwise, it would benefit when you use 3rd party websites that help you to
convert the credentials into base64.
20) What are the different scopes of an environment variable in
Postman?
Scope of a variable in Postman is defined as the boundaries it can access.
Here are important scopes of an environment variable in Postman:
● Local Scope: This type of variable can be accessed only in the
environment in which it was created
● Global Scope: This type of variable can be accessed globally in any
environment or no environment.
21) Is it possible to import local variables in Postman Monitors?
Postman monitors allow you to import local variables but not global variables.
22) What is the Postman execution order for a collection?
For all the requests in a collection, the scripts will execute in the following
given order:
Step 1) A pre-request script associated with a collection will run before every
request.
Step 2) A pre-request script associated with a folder will run before every
request in a specific folder.
Step 3) A test script associated with a collection will run after every request.
Step 4) A test script associated with a folder will run after the request in the
specific folder.
23) Can you have two global scope variables with the same name in
Postman?
No, the global scope never has duplicate/same names, while variables having
local scope can have the same name in various environments.
24) How do you access postman variables?
You can log the variable values in the console by using the command:

console. Log (pm. Variables.

25) What is the use of the collection in Postman?


In Postman, a collection is used to group similar requests. It helps you to
arrange requests systematically into folders.
26) How can you use POSTMAN to generate random numbers in a
specific range?
In your Pre-request script define your variable with:

pm.globals.set('randomNum', Math.floor(Math.random() *
5));

Then in your URL call your variable in the URL like so:
Output:

{{randomNum}}

27) How do you remove local variables?


Local variables are automatically removed once the tests have been
executed.
28) What is ‘Postman Collection runners?
Postman contains a collection runner that is useful for automating API testing.
It helps visualize details of each iteration and test results. A postman
collection runner is also used for Data-driven testing.
29) What do you mean by postman monitors?
The postman monitor feature is used for running collections until the user’s
specified time. However, the user must be logged in to their account to use
this feature.
30) Why saving your work in the Postman cloud is not advisable?
You should not save your work in Postman as your business details do not
remain confidential. Moreover, saving your on-Postman cloud may cause a
security breach as it requires sign-in. Therefore, saving your work in the
Postman cloud is not advisable.
31) What are the standard rules of an API test design?
Here are the key principles of an API test design:
1. Setup: Create objects, start services, and initialize data.
2. Execution: Apply API or the scenario, including logging
3. Verification: It is use for evaluating the result of the execution
4. Reporting: Indicates Pass, failed, or blocked status
5. Clean up: Pre-test state
32) What is the Team workspace in Postman?
A Team workspace is a synergetic environment for users where many
programmers may develop APIs, provides feedback, and collaborate on the
same pools of requests. It also helps to synchronize and collaborates all the
team’s work in one place.
33) What is the 301-status code?
301 status code represents a permanent redirect from one website page to
another. It tells the search engines that the old page has become outdated,
and the engine has to index the new page or URL.
34) What is status code 201?
Status code 201 is created only when a resource is successfully created using
a PUT or POST request. It returns a link to a newly created one with the help
of the location header.
35) What is the procedure to remove local variables?
The local variables can be automatically removed when you have executed
and completed the tests.
36) What is Pre-Request Script in Postman?
In Postman, a pre-request script is a set of rules that runs before executing a
request.
37) How are Query Parameters different from Path Variables?
In Postman, Path Variables are used to identify specific resources, and Query
Parameters are used to sort or filter the resources.
38) What are the main drawbacks of Postman?
Here are some cons/ disadvantages of using Postman:
● Postman cannot process more than 1000 API requests.
● It is not easy to manage the collections and requests in a massive size
project.
● Postman is not an ideal API tool for workspace management in the form
of code as there can be lots of code duplication while handing the
dynamic API requests.
39) What are some of the JS libraries available in Postman?
Some JS libraries available in Postman are
1) Lodash
2) Moment
3) GUID
40) What is GUID?
GUID is short for Global Unique Identifier. It is hexadecimal digits that are
separated by hyphens. This Postman identifier GUID solves the purpose of
uniqueness.
41) How can you view log requests and responses in Postman?
You can use the Postman Console window to view request logs and response
logs.
42) What is the importance of setNextRequest in Postman?
setNextRequest helps you to define the workflow. It is needed to change the
order of the requests being executed.
43) What test code allows you to check whether the response status is
200 or not?
Following is a test code to check whether the response status is 200 or not:

tests[“Status Code is 200”] = responseCode.code === 200;

44) What do you understand by ScratchPad?


Scratch Pad is a place which is provided by Postman that helps you work
without the need to connect with Postman servers.
45) How can you iterate a request 100 times in Postman?
You can iterate a request 100 times in Postman by using Collection Runner.
46) What would happen if {{$randomInt}} dynamic variable is added?
You need to add a random integer between 0 and 1000.
47) How do you access variable values from a file inside pre-request and
test scripts?

data.var_name

data['var_name']

48) Can you read the Postman Chrome application to read and write
cookies?
No, it is impossible to read and write cookies using the app.
49) Which programming language is used for Postman tests?
JavaScript is used for Postman tests.
50) Which tool can be used to run Postman Collections in Jenkins?
Newman can be used to run Postman Collection in Jenkins.

You might also like