Postman - Guru99
Postman - Guru99
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.
● 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
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 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!
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.
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.
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.
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.
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.
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
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"));
{{variable name}}
pm.globals.set('randomNum', Math.floor(Math.random() *
5));
Then in your URL call your variable in the URL like so:
Output:
{{randomNum}}
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.