0% found this document useful (0 votes)
15 views10 pages

API Testing with Postman Guide

The document provides an overview of API testing using Postman, detailing its features such as a powerful JS editor, integration with NewMan for CLI automation, and various workspace types. It explains how to create API requests, manage environments and variables, and execute scripts in a specific order to validate API responses. Additionally, it covers advanced topics like data-driven testing, error handling, and JSON schema validation to ensure robust API testing practices.

Uploaded by

Rohit Lavate
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
0% found this document useful (0 votes)
15 views10 pages

API Testing with Postman Guide

The document provides an overview of API testing using Postman, detailing its features such as a powerful JS editor, integration with NewMan for CLI automation, and various workspace types. It explains how to create API requests, manage environments and variables, and execute scripts in a specific order to validate API responses. Additionally, it covers advanced topics like data-driven testing, error handling, and JSON schema validation to ensure robust API testing practices.

Uploaded by

Rohit Lavate
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

API Testing Postman

-Comes with powerful JS Editor(Postman Object)-->Helps to perform Assertions(Validates test) -Ready Made features of framework-->variables, environements, workflows, data
driven components and pm object which helps quickly setup automation quickly -Powerful integration with NewMan tool, to run the automated tests from CLI, later can be integrated
with Jenkins for CI/CD integration

Types of workspaces-->Personal(internal),Partner(Team), public -->visibility to everyone Collections-->Group set of API Requests

Example: -Create Library collection: Base URL: [Link] ([Link] -AddBook Request Base URL + Resource:---
>[Link] Body: { "name":"Java", "isbn":"abn23", "aisle":"1234", "author":"prime" } -GetBook Request Base URL + Resource:---
>[Link] -DeleteBook Request Base URL + Resource:--->[Link]
Body: { "ID": "abn231234" }

--Environments in Postman: -An Environment is a set of variables, you can use in your postman [Link] can use environments to group related set of values together and
manage access to shared postman data, if you are working as a part of team -Variables allow you to store and reuse values in your requests and scripts. By storing a value in a
variable, you can reference it throughout your collection,environements and requests and if you need to update the value, you only have to change it in one place. Using variable
increases your ability to work efficiently and minimize the likelihood of error. -Environments tab-->Create environment-->create variable and set variable in the request by selecting
and double clicking that hardcoded value.

--Variable scopes:-->Postman supports following variable scopes -Global -Collection -Environment -Data (Rarely used) -Local (Rarely used) Environments-->Global(Common
variables to entire postman workspace) Collection-->Variables tab(can be accessed within that collection, request part of this collection will access it) Environment variables-->specific
to environment Data variable-->for data driven testing Local variable-->specific to request Note: If variable with same name is declared in 2 different scopes, the value stored in
variable with narrower scope will be used.

POSTMAN

GLOBAL VARIABLES

COLLECTION VARIABLES

+------------------------------+ | | | | ENVIRONMENT VARIABLES | | | | | | | | | | +----------------------+ | | | | | | DATA VARIABLES | | | | | | | | | | | | | | +----------------+ | | | | | | | | LOCAL


VARIABLES | | | | | | | | +----------------+ | | | | | | +----------------------+ | | | | +------------------------------+ | | |

Scripting in Postman:
-Postman contains runtime based NodeJs that allows to add dynamic behavior to requests and collections. This allows us to write Test Suits, buld requests that can contain dynamic
parameters, pass data between requests

===================================
POSTMAN SCRIPT EXECUTION ORDER
(ONE SNAP)
STEP 1: COLLECTION PRE-REQUEST SCRIPT
• Runs first • Executes before every request in the collection • Used for:

Setting common variables


Auth token generation
Reusable setup logic

STEP 2: FOLDER PRE-REQUEST SCRIPT


• Runs after collection pre-request • Applies only to requests inside the folder • Used for folder-specific setup
STEP 3: REQUEST PRE-REQUEST SCRIPT
• Runs just before the request is sent • Used for:

Dynamic headers
Timestamp, random values
Updating variables

STEP 4: REQUEST IS SENT TO SERVER


• Actual API call happens • Variables are resolved here • Request hits backend server

STEP 5: RESPONSE RECEIVED


• Response returned from server • Status code, headers, body available

STEP 6: REQUEST TEST SCRIPT


• Executes after response is received • Used for:

Validations (status code, body)


Assertions
Extracting values to variables

STEP 7: FOLDER TEST SCRIPT


• Runs after request test script • Applies to all requests in the folder

STEP 8: COLLECTION TEST SCRIPT


• Runs last • Used for:

Common validations
Cleanup
Logging

In Postman, scripts execute in the order: Collection pre-request → Folder pre-request → Request pre-request → Request → Request test → Folder test → Collection test.

Go to Any collection-->Any Request-->Scripts-->Pre-request,post-response(Assertions here)

--The pm Object--> You will carry out most of POSTMAN JS API functionality using "pm" which provides access to request and response data and variable. [Link]("",)-->Takes two
arguments, description and function where we write code.

const jsonData = [Link](); [Link]("validate status code is 200", function() { [Link](200); [Link](jsonData).[Link]("Msg");
[Link]([Link]).[Link]("successfully added"); });

--Dynamically generate values for variable Rule: isbn should start with RS and then dynamically generate values(Pre Request script)-->RS is constant, we can use as Global varible
as "CompanyCode" At collection level set isbn as new variable

const code = [Link]("CompanyCode"); const val = [Link]('{{$randomInt}}'); [Link]("isbn",code+val); const jsonData = [Link]();
[Link]("validate status code is 200", function() { [Link](200); [Link](jsonData).[Link]("Msg"); [Link]([Link]).[Link]("successfully
added"); }); //checking header contains Content-Type [Link]("Header cookies response time validations",function() { [Link]([Link]("Content-
Type")).[Link]("application/json;charset=UTF-8"); [Link]([Link]).[Link](400); [Link]([Link]()).[Link]("successfully added"); });

--Running set of tests together


So in tests scripts, access this ID and store somewhere, from which GetBook and DeleteBook can access it. Go to Environments(UAT and QA)-->create variable, book_id(At runtime
script will update it)

const code = [Link]("CompanyCode"); const val = [Link]('{{$randomInt}}'); [Link]("isbn",code+val); const jsonData = [Link]();
const bookId = [Link]; [Link]([Link]); [Link]("book_id",bookId); [Link]("validate status code is 200", function() { [Link](200);
[Link](jsonData).[Link]("Msg"); [Link]([Link]).[Link]("successfully added"); }); [Link]("Header cookies response time validations",function() {
[Link]([Link]("Content-Type")).[Link]("application/json;charset=UTF-8"); [Link]([Link]).[Link](400);
[Link]([Link]()).[Link]("successfully added"); });

-Go to GetBook and in 'params'-->set ID from environment variable-->{{book_id}} -same for DeleteBook -Go to collection level and run

--Validate response with the Input data of other API through Automated Code -AddBook API const code = [Link]("CompanyCode"); const val =
[Link]('{{$randomInt}}'); [Link]("isbn",code+val); [Link]("author_name","Rohit Prime"); const jsonData = [Link]();
const bookId = [Link]; [Link]([Link]); [Link]("book_id",bookId); [Link]("validate status code is 200", function() { [Link](200);
[Link](jsonData).[Link]("Msg"); [Link]([Link]).[Link]("successfully added"); }); [Link]("Header cookies response time validations",function() {
[Link]([Link]("Content-Type")).[Link]("application/json;charset=UTF-8"); [Link]([Link]).[Link](400);
[Link]([Link]()).[Link]("successfully added"); });

-GetBook API const getBookResponse = [Link](); [Link](getBookResponse); [Link]("Validate JSON response logic",function() {
[Link](getBookResponse[0].author).[Link]([Link]("author_name")); });

--JSON Schema validating


-We get the JSON output with four fields,every field accepting String, what your response expect and what is dataType. so check response what we get is matching with JSON
Schema. -JSON Schema generator(Google it)-->Add expected JSON and Generate the schema. -If all fields are mandatory then keep them in required(in Schema)

const getBookResponse = [Link](); [Link](getBookResponse); const schema = { "type": "array", "items": [ { "type": "object", "properties": { "book_name": { "type":
"string" }, "isbn": { "type": "string" }, "aisle": { "type": "string" }, "author": { "type": "string" } }, "required": [ "book_name", "isbn", "aisle", "author" ] } ] }; [Link]("Validate JSON response
logic",function() { [Link](getBookResponse[0].author).[Link]([Link]("author_name")); });

[Link]("Validate the JSON response schema",function(){ [Link](schema); });

-DeletBook const schema = { "type": "object", "properties": { "msg": { "type": "string" } }, "required": [ "msg" ] }; [Link]("Validate the message after succesful operation",function() {
const jsonData = [Link](); [Link]([Link]).[Link]("book is successfully deleted"); }); [Link]("validating the schema for DeleteBook API",function() {
[Link](schema); });

-For Functional validation--> bookId should be isbn(get from collection variable) + aisle(Present in request-->[Link]() is not present, so we have to access request body in raw
format and then convert to JSON) const code = [Link]("CompanyCode"); const val = [Link]('{{$randomInt}}');

[Link]("isbn", code + val); [Link]("author_name", "Rohit Prime");

const jsonData = [Link](); const bookId = [Link]; [Link]("book_id", bookId);

[Link]("validate status code is 200", function () { [Link](200); [Link](jsonData).[Link]("Msg"); [Link]([Link]).[Link]("successfully


added"); });

[Link]("Header cookies response time validations", function () { [Link]([Link]("Content-Type")).[Link]("application/json;charset=UTF-8");


[Link]([Link]).[Link](400); [Link]([Link]()).[Link]("successfully added"); });

[Link]("ID Logic validation", function () { const req = [Link]([Link]);

[Link](req).[Link]("isbn");
[Link](req).[Link]("aisle");

const expected_id = [Link] + [Link];


[Link](expected_id).[Link](bookId);

});

Alternate way: [Link]("ID Logic validation", function () { const req = [Link] && [Link] ? [Link]([Link]) : ;

const expected_id = ([Link] || "") + ([Link] || "");


[Link](req).[Link]("isbn");
[Link](req).[Link]("aisle");

[Link](expected_id).[Link](bookId);

});

--Data Driven Testing:


-For isbn and aisle, we have generator, but name and author we have to get from the document. -[Link] BookName,Author Spring,Natraj Chowdhary Postman,Rahul Shetty
Git,Narsi Angular,Sudhakar Sharma
-add 'book_name' variable at collection level

-Modified_script: const code = [Link]("CompanyCode"); const val = [Link]('{{$randomInt}}');

[Link]("isbn", code + val); //[Link]("author_name", "Rohit Prime");


[Link]("book_name",[Link]("BookName")); [Link]("author_name",[Link]("Author"))
[Link]([Link]("author_name"));

const jsonData = [Link](); const bookId = [Link]; [Link]("book_id", bookId);

[Link]("validate status code is 200", function () { [Link](200); [Link](jsonData).[Link]("Msg"); [Link]([Link]).[Link]("successfully


added"); });

[Link]("Header cookies response time validations", function () { [Link]([Link]("Content-Type")).[Link]("application/json;charset=UTF-8");


[Link]([Link]).[Link](400); [Link]([Link]()).[Link]("successfully added"); });

[Link]("ID Logic validation", function () { //const isbn_val = [Link]("isbn"); const req = [Link]([Link]);

[Link](req).[Link]("isbn");
[Link](req).[Link]("aisle");

const expected_id = [Link] + [Link];


[Link](expected_id).[Link](bookId);

});

Now go to collection level -->click on Run-->Click on Select File-->Run Library(i.e Run Collection)

For Delay [Link]("Delay test by 2 seconds", function (done) { setTimeout(function () { [Link]([Link]).[Link](200); done(); }, 1000); // 2000 ms = 2 seconds });

--Error Handling Scenarios: Consider same bookId generated for AddBook request-->It will throw error, Book already exists replace: { "name":"{{book_name}}", "isbn":"{{isbn}}",
"aisle":"8772", "author":"{{author_name}}" }

with: { "name":"{{book_name}}", "isbn":"RS11", "aisle":"8772", "author":"{{author_name}}" }

Modify Test: For AddBook


const code = [Link]("CompanyCode"); const val = [Link]('{{$randomInt}}');

[Link]("isbn", code + val); //[Link]("author_name", "Rohit Prime");


[Link]("book_name",[Link]("BookName")); [Link]("author_name",[Link]("Author"));
[Link]([Link]("author_name"));

const jsonData = [Link](); const bookId = [Link]; [Link]("book_id", bookId); function generateBookId() { var req = [Link]([Link]);
const expected_id = [Link] + [Link]; return expected_id; } function cleanupScript() { const book_id = generateBookId(); [Link]("book_id",book_id);
[Link]("DeleteBook"); } [Link]("validate status code is 200", function () { try { [Link](200); [Link](jsonData).[Link]("Msg");
[Link]([Link]).[Link]("successfully added"); } catch(err) { //check if error is due to already book exists if([Link]("Exists")) { cleanupScript(); } } });

[Link]("Header cookies response time validations", function () { [Link]([Link]("Content-Type")).[Link]("application/json;charset=UTF-8");


[Link]([Link]).[Link](400); [Link]([Link]()).[Link]("successfully added"); });

[Link]("ID Logic validation", function () { //const isbn_val = [Link]("isbn"); const req = [Link]([Link]);

[Link](req).[Link]("isbn");
[Link](req).[Link]("aisle");

const expected_id = [Link] + [Link];


[Link](expected_id).[Link](bookId);

});

// [Link]("Delay test by 2 seconds", function (done) { // setTimeout(function () { // [Link]([Link]).[Link](200); // done(); // }, 1000); // 2000 ms = 2 seconds // });

Modify Test: For DeleteBook


. . . [Link]("Validate the message after succesful operation",function() { const jsonData = [Link](); [Link]([Link]).[Link]("book is successfully deleted");
[Link]("AddBook"); //But it may create issue,as continuous loop,so set flag in collection level as false });
===================================
[Link] vs
[Link]
Feature [Link] [Link]
API type Legacy Modern
Namespace postman [Link]
Current support Supported Supported
Recommended for new code No Yes
Runner/Newman required Yes Yes
Works with Send button No No
Future-proof ⚠ Maybe Yes

Note: “Both methods do the same thing. [Link]() is legacy, while [Link]() is the newer, recommended API. Both work only in runner-based
executions.”

Modified Test After setting flag: AddBook


const code = [Link]("CompanyCode"); const val = [Link]('{{$randomInt}}');

[Link]("isbn", code + val); //[Link]("author_name", "Rohit Prime");


//[Link]("book_name",[Link]("BookName")); //[Link]("author_name",[Link]("Author"));
[Link]([Link]("author_name"));

const jsonData = [Link](); const bookId = [Link]; [Link]("book_id", bookId); function generateBookId() { var req = [Link]([Link]);
const expected_id = [Link] + [Link]; return expected_id; } function cleanupScript() { const book_id = generateBookId(); [Link]("book_id",book_id);
[Link]("calling DeleteBook"); [Link]("flag",true); [Link]("DeleteBook"); //[Link]("DeleteBook"); } [Link]("validate
status code is 200", function () { try { [Link](200); [Link](jsonData).[Link]("Msg"); [Link]([Link]).[Link]("successfully added"); }
catch(err) { //check if error is due to already book exists if([Link]("Exists")) { cleanupScript(); } } });

[Link]("Header cookies response time validations", function () { [Link]([Link]("Content-Type")).[Link]("application/json;charset=UTF-8");


[Link]([Link]).[Link](2000); //[Link]([Link]()).[Link]("successfully added"); });

[Link]("ID Logic validation", function () { //const isbn_val = [Link]("isbn"); const req = [Link]([Link]);

[Link](req).[Link]("isbn");
[Link](req).[Link]("aisle");

const expected_id = [Link] + [Link];


[Link](expected_id).[Link](bookId);

});

// [Link]("Delay test by 2 seconds", function (done) { // setTimeout(function () { // [Link]([Link]).[Link](200); // done(); // }, 1000); // 2000 ms = 2 seconds // });

DeleteBook:
const schema = { "type": "object", "properties": { "msg": { "type": "string" } }, "required": [ "msg" ] }; [Link]("Validate the message after succesful operation",function() { const jsonData
= [Link](); [Link]([Link]).[Link]("book is successfully deleted"); if([Link]("flag")) { [Link]("AddBook");
[Link]("flag",false); } }); [Link]("validating the schema for DeleteBook API",function() { [Link](schema); });

Note: set back request body to { "name":"{{book_name}}", "isbn":"{{isbn}}", "aisle":"8772", "author":"{{author_name}}" } -Run again with [Link]

--Handling OAuth 2.0 Authenticated Google API's:(example:


Sign In with Google)
-Below details are required: Client,ClientId,Client Secret Id,Resource Owner, Resource/Authorization Server -Steps: -User signs into google by hitting Google Authorization Server
and Get Code -Application will use this code to hit Google Resource server in back end to get Access Token -Application grants access to user by validating Access Token

-Why Applications Rely on other (Google or Facebook) authentication?-->No data breach,no user profile data required,common login
Collection Pre-request ↓ Generate OAuth token (if expired) ↓ Store access_token ↓ Attach token to request ↓ Call protected API ↓ Validate response

Grant Type Authorization flow:


User Browser | | 1) Click "Login with Google" v BookMyShow (Client App) | | 2) Redirect to Google Auth URL (client_id, scope, redirect_uri) v Google Authorization Server | | 3) User
logs in + gives consent | 4) Redirect back with Authorization Code v BookMyShow Backend | | 5) Exchange Code + client_secret for Access Token v Google Token Endpoint | | 6)
Returns access_token (+ refresh_token / id_token) v BookMyShow Backend | | 7) Use access_token to call Google Resource APIs v Google Resource Server (UserInfo APIs)

When you sign in to an app like BookMyShow using Google, the app uses OAuth 2.0 Authorization Code flow. Step-by-step flow --BookMyShow creates a Google login URL
(Authorization URL) This URL is unique for that application because it contains:client_id (public),redirect_uri, scope (what data is requested: email, profile,
etc.),response_type=code Client Secret is never exposed in the browser. --User is redirected to Google Authorization Server User enters Google credentials then,Google verifies the
user (authentication).Google also asks consent (permissions) based on scope --Google sends Authorization Code back to BookMyShow Google redirects to BookMyShow’s
redirect_uri with:code=AUTHORIZATION_CODE This authorization code is short-lived (like a one-time code).(It’s not exactly OTP, but similar idea.) --BookMyShow exchanges
Authorization Code for Access Token BookMyShow backend (server-side) sends a request to Google Token Endpoint It includes:authorization code,client_id,client_secret (only on
server, not visible to user),redirect_uri,grant_type=authorization_code --Google returns tokens Google responds with:access_token (used to call APIs),expires_in sometimes
refresh_token (to get new access tokens without login again),sometimes id_token (OpenID Connect, contains user identity) --BookMyShow calls Google Resource APIs
BookMyShow uses access_token to fetch user info like:name,email,profile picture(based on scope) --BookMyShow creates its own session BookMyShow stores a session
(cookie/JWT) in the browser For every next operation, BookMyShow uses: its own session token (most common) and/or access token when it needs Google APIs

-->Create collection-->OAuth 2.0


OAUTH 2.0 – AUTHORIZATION CODE
CONFIGURATION
Grant Type
Authorization Code

Redirect URL / Callback URL


[Link] ([Link]

Authorization Server URL


[Link] ([Link]

Access Token URL


[Link] ([Link]

Client ID
[Link]

Client Secret
erZOWM9g3UtwNRj340YYaK_W

Scope
[Link] ([Link]

State
Any random string (example: abc123xyz)
How to pass OAuth in API Request

Headers Authorization: Bearer


<access_token>
===================================
OAUTH 2.0 – AUTHORIZATION CODE
FLOW (MANDATORY FIELDS)
1. GET AUTHORIZATION CODE REQUEST

Purpose:
Used to authenticate the user and obtain an Authorization Code from the Authorization Server.

Endpoint:
Authorization Server URL

Example:
[Link] ([Link]

Mandatory Query Parameters:


scope client_id response_type=code redirect_uri state (recommended for security)

Output:
Authorization Code (example: code=4/0AX4XfWj...)

2. GET ACCESS TOKEN REQUEST

Purpose:
Used by the client application to exchange Authorization Code for Access Token.

Endpoint:
Access Token URL

Example:
[Link] ([Link]

Mandatory Parameters:
code client_id client_secret redirect_uri grant_type=authorization_code
Request Method:
POST

Request Body Type:


application/x-www-form-urlencoded

Output:

Access Token (example:


access_token=ya29.a0AfH6SMD...)
OAuth 2.0 project:[Link]

Mock Servers and Schema validation:


-[Link] -Based on schema, you should be able to create json, their are some tools which create example, if we pass JSON Schema [Link]
[Link]/online-json-to-schema-converter ([Link]

-Mock Servers: A mock API Server imitates a real API server by providing realistic mock API response to [Link] postman, you can make requests that return mock data
defined if you do not have production API ready, or you do not want to run your requests against real data yet e.g--> {{base_url}}/getapitestingcourses --> If this endpoint is under
development, we have to tell postman to create mock_server {{base_url}}/getcoursedetails?name={{course}} Mock server: {{mock_server_url}}/getapitestingcourses ---->Give
postman sample response you expect(configure it)-->Based on it we can write code, which will be valid for real api

-Automatically environment will be created -to create mock server-->Go to mock server tab(below collection)--> create a new mock server-->create a new colllectiorn->add request
method,Request URL,Response code, response body<-----(configure all these field in table) give name to mock server -->MockAPITesting copy mock server URL--->e.g
[Link] ([Link] { "data": [ { "course": "Postman", "price": 150,
"category": "JavaScript" }, { "course": "SOAPUI", "price": 25, "category": "Groovy" }, { "course": "Rest Assured", "price": 120, "category": "Java" }, { "course": "Selenium", "price": 200,
"category": "Java" }, { "course": "Cypress", "price": 180, "category": "JavaScript" }, { "course": "Playwright", "price": 170, "category": "TypeScript" } ] }

Go to mock server-->click on collection link inside it-->go to set up tab-->click on request link Hit it now when code is ready simply switch environment to QA/UAT, url available in that
environment will be hit -we can write script as well

SOAP Webservices in Postman:


Rest API's uses HTTP Protocol to send the request and receive the response whereas SOAP Webservices/API's uses SOAP protocol to send the request and receive the response
End Point: [Link] ([Link]

[Link] ([Link]
[Link] ([Link]
WSDL) [Link] ([Link]
[Link] ([Link]
[Link] ([Link] [Link]
([Link] [Link] ([Link]
[Link] ([Link] [Link]
wsdl ([Link] [Link] ([Link] SOAP
WebServices

Download WSDL from [Link] ([Link] and import it in Postman

const responseJson = xml2Json([Link]()); [Link](responseJson); const expected =


Number([Link]("number1"))+Number([Link]("number2")); [Link]("Validate Addition in the response",function() { //const expected =
Number([Link]("number1"))+Number([Link]("number2")); const actualValue = Number(responseJson["soap:Envelope"]["soap:Body"]
["AddResponse"]["AddResult"]); [Link](expected).[Link](actualValue); }); [Link]("Validate Addition in the response method 2",function() { [Link](200);
[Link]([Link]()).[Link](expected); });

--Newman: It is commandline collection runner for postman


-It allows you to run and test a postman collecion directly from the command line -Using Newman, you can easily integrate it with your CI servers and build system -Newman built on
nodejs to run newman-->Install Nodejs as prerequisite -Install Newman from NPM globally on your system, which allows you to run it from anywhere command: npm install -g
newman -To run collection from NewMan command: $newman run -Generate HTML report for test execution results with newman -htmlextra plugin
[Link] ([Link] -Integrate Postman Automation Script to Jenkins CICD
with help of Newman commands

Steps to run: Export collection file to local(Collection v2.1)-->select enviroment and then export and also export json files for all environments) Open terminal and navigate to directory
where file located(Also paster csv file which needed at same location) (FileName should be underscore, no spaces should be their) run command: newman run
Library.postman_collection.json -d [Link] -e QA.postman_environment.json -g workspace.postman_globals.json

newman run Library.postman_collection.json


-d [Link]
-e QA.postman_environment.json
-g workspace.postman_globals.json

Here -d : data driven


-e : Environment variables
-g : Global variables

HTML Report: [Link] ([Link] Install Globally npm i -g newman-reporter-


htmlextra

newman run Library.postman_collection.json -d [Link] -e QA.postman_environment.json -g workspace.postman_glo

newman folder will be created contains html file

--Set Up Jenkins:
-Download Generic Java Package(.war): [Link] ([Link] -open cmd as admin and run command: java -jar [Link] -httpPort:9090 -Go to
localhost:9090 in browser and setup username and password -Go to Jenkins Dashboard, select New Item -Freestyle project -On Configuration page-->Build triggers tab-->Build
steps-->Execute windows batch command(For windows)/Execute shell(For Mac or linux)-->Paste commands D: cd Testing Prep\Selenium Practice\Projects newman run
Library.postman_collection.json -d [Link] -e QA.postman_environment.json -g workspace.postman_globals.json -r htmlextra

Parameterize jenkins--> go to job -->configure-->General tab-->Select-->This project is Prameterized-->Click on Add Parameter-->Select choice parameter(From Dropdown) --
>Choice parameter-->Name as 'Environment'-->Choices as QA, UAT -->Go to Build-->Execute windows batch command-->command-->"$Env".postman(new command added this)
D: cd Testing Prep\Selenium Practice\Projects newman run Library.postman_collection.json -d [Link] -e "%Environment%".postman_environment.json -g
workspace.postman_globals.json

cd /d "D:\Testing Prep\Selenium Practice\Projects"

echo Selected Environment = %Environment%

newman run Library.postman_collection.json ^ -d [Link] ^ -e "%Environment%.postman_environment.json" ^ -g workspace.postman_globals.json ^ -r cli,htmlextra

-->Build with parameter

--Version control features: -Share collection, push to workspaces -Share public link -Create a fork(Option available for collection)-->Fork label-->Click on Fork Collection -Make
changes and click on create pull request-->Approve and Merge -We can Delete source of changes

--Add Monitor: To run collection periodically to check for its performance and response Create a monitor-->Monitor Name->Smoke test Collection->Library Collection Version Tag-
>Current Environment->QA Run this monitor-->Frequency(e.g->minute,day etc) Select Receive mails Select retry if fials->2 times Click on create

-At bottom test runner is available, Trash is also available

Project:
-Flow:-> Login API-->Create Product-->Purchase Order on created product-->Delete Order -URL: [Link]/client/auth/login --->Register and create login -Inspect
page before and after login to see the network calls, as we don't have documentation we should be able to create documentation from browser onlu. -When we login we get the token
in response, which used in all subsequent calls(Token tells who we are)

--Create API Collection:-->ECOM -Open login page-->Go to Inspect(Network calls)-->see 'login' call-->check Header for request URL-->Add request 'login' in collection which is POST
call URL--> [Link] ([Link] Body: From Payload get it {
"userEmail":"lavatero92@[Link]", "userPassword":"Admin@123" } Copy the token and userId and set it to collection variables
const jsonData = [Link](); const userId = [Link]; [Link](userId); [Link]("userId",userId);
[Link]("token",[Link]); [Link]("Validating Login",function() { [Link]([Link]).[Link]("Login Successfully"); });

-Add new Product-->Create new request for it 'CreateProduct' EndPoint: [Link]


([Link] HTTP Method= POST Add Auth token in header with key as 'Authorization' Form Data: Paste below details after click
on bulk edit productName: iPhone ProductAddedBy: {{userId}} productCategory: Electronics productSubCategory: Mobile productPrice: 85000 productDescription: Macintosh
productFor: Unisex productImage: (allow file reading from outside directory)

Response we get product id { "productId": "695b4221c941646b7a7e5e78", "message": "Product Added Successfully" }

check on [Link] ([Link] if product added or not

const jsonData = [Link](); [Link]("productId",[Link]); [Link]("Verifying Product added to category",function() {


[Link]([Link]).[Link]("Product Added Successfully"); });

-Now let us 'CreateOrder' i.e Place Oreder URL: [Link] ([Link] HTTP
Method: POST { "orders": [ { "country": "India", "productOrderedId": "{{productId}}" } ] }

Header: Add 'Authorization'

Response: { "orders": [ "695b4bcdc941646b7a7e6d09" ], "productOrderId": [ "695b4badc941646b7a7e6cff" ], "message": "Order Placed Successfully" }

const jsonData = [Link](); const orderId = [Link][0]; [Link](orderId); [Link]("orderId",orderId); [Link]("Verifying product order
placement",function() { [Link]([Link]).[Link]("Order Placed Successfully"); });

-Now let us 'GetOderDetails' URL: [Link] ([Link]


details?id=%7B%7BorderId%7D%7D) Header: Add 'Authorization'

const jsonData = [Link](); [Link]("Verifying order details",function() { [Link]([Link]).[Link]([Link]("productName")); });

-Now let us 'DeleteProduct' URL: [Link] ([Link]


product/%7B%7BproductId%7D%7D) HTTP Method: DELETE

[Link]("Validating Status code",function() { [Link](200); });

You might also like