Ads

PostMan Notes

 writting Test scripts in Postman:

pm.test("checking the response code",function(){ pm.response.to.have.status(200); }); pm.test("checking the request headers",function(){ let requestHeader=pm.request.headers.get("Content-Type"); pm.expect(requestHeader).to.eql("application/json"); pm.expect(requestHeader).to.include("json"); }) pm.test("checking response headers",function(){ let responseHeaders=pm.response.headers.get("Content_type"); pm.expect(responseHeaders).to.include("json"); }) pm.test("checking the response time",function(){ pm.expect(pm.response.responsetime).to.be.lessThan(3000); }) pm.test("Validating the response",function(){ const json=pm.response.json(); pm.expect(json.data).to.be.an('object'); pm.expect(json.data.languages[0]).to.exist; pm.expect(json.data.languages).to.be.an('array'); pm.expect(json.data.languages).to.have.lengthOf.at.least(2); const languageList=json.data.languages; languageList.forEach((language)=>{ pm.expect(language.language).to.be.a('string').and.to.not.be.empty; }) pm.expect(json.data.languages[0].language).to.be.a('string').and.to.not.be.empty; }) pm.test("to set env variable",function(){ const json=pm.response.json() const firstLanguage=json.data.languages[0].language; pm.globals.set('firstLanguage'); console.log(pm.globals.get('firstLanguage')) } pm.environment.get("authtoken"); let value=pm.iterationData.get(key)

Authentication:

the process of verifying who u are

Authorization:

Authorised person what are all the access he has

Types:

No auth--->no authentication required

Basic auth--->simple we have to pass username,password

Bearer token--->header only we can pass this token prefixed with Bearer

APi key---->we can use this directly to access the resources

Oauth 1.0--.->we have to consumer key,consumer secret,accesstoken,token secret

Oauth 2.0--direct token(Actual flow is user will be navigated to the authorisation server,there they need to login,it will give authorisation code,that code will be for access

initially one api will be there to hit particular auth api,it will give response with access token,this access token will be sent to oauth2(token)

Digest auth--->similar to basic auth,additionally we have to pass Some alogirthms like nonce,qop,realm

 

Variables:

Global variables--->common accross all collections

Collection variable--->we can set environment per collection,,{{variableName}}

 

Data from External file:

csv or excel file can be passed as external data during running the collection..this also can be refered nby same “{{firstname}}”

this file values can be get by pm.iterationdata.get(key)

 

Pre Request & Post Request:

Pre request can be set in Collection,folder,request level---this will execute before running the request

Collection pre--->folder pre--->request pre--->request

Post Request can be set Collection,Folder,request level-->this will execute after running the request

request-->post request--->folder level request--->collection request

 

Monitors:

Monitors are like pipeline we can schedule the collection to run at specific time.

WorkFlows:

like chanining the requests

Chaining way:

postman.setNextRequest();

 

New MAn Run:

npm install -g newman

share the json link of collection

newman run https://api.postman.com/collections/20843134-da4c9a1b-b906-4c99-ac89-2b55a281f1bc?access_key=PMAT-01J4K5ZQNN8SN313JXD3CF7JCE

-n----->number of times

-r---------->report

-d ----------->external data

Reporters:

npm i -g newman -reporter -htmlextra

npm i -g newman -reporter -junitfull

newman run https:json -d data.csv -n 3 -r junit -r htmlextra

 

Mockup:(Fake Data):

Create Mock Server--->give Status code ,REsponse body,Payload,request method,end point whatever u want

run the url with that end point,it gives mock api.

Comments

Popular posts from this blog

Appium Notes

Rest Assured Api Automation

Jenkins Notes