Session 3: API Testing | Postman | How To Create Own API's | JSON (Java Script Object Notation)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign so in the today's session uh we are  going to see how we can create our own apis   in the last class we have seen so how we can  uh send API requests to different type of API   request and we have taken a small dummy API and  then we have seen how we can send different type   of APA request or HTTP request so today we  are going to see how we can install or how   we can create our own apis for testing purpose  okay now the first thing is uh to create our   own apis we have to install a few softwares  and then we will able to create our own apis   right so to install AR to create any apis right  our own apis or some demo apis we need to install   some softwares so what are the softwares we  need to install the first thing is we need   to install something called node.js software  okay so node.js it is a free software which   you haven't just download and install it so we  installed node.js software so we will also get   one thing called npm node package manager npm is  node package manager node package manager and this   particular component will automatically come along  with the node.js because we need this component to   run the or to create our own apis so first we  need to install node.js software first thing   second thing is what when you install node.js by  default you will get npm it is the same process   on Mac also so you can follow the same process so  we need to install node.js first and then we we   will get npm node market manager by default you  will get along with the node.js you don't need   to install this separately and once you get this  node package manager by using this node package   manager or by using this mpm we have to install  Json server okay we have to install Json server   this is also one of the software so step one we  have to download node.js and we need to install it   second thing is we will get npm package by default  along with the node.js and this is part of node.js   actually so once you get an npm package by using  this npm we can install Json server okay these   are the three things which we need to have again  I'm repeating step one we have to install node.js   software second thing is what you have to install  Json server by using npm so why where we will get   an npm this npm will come along with the node.js  okay so these are the three things which we need   to have so first let us see step by step how we  can download and install node.js and then how we   can install Json server by using npm it's very  simple and straightforward let me show you how   we can do it in the MAC Mission also you have to  follow the same mission same process same commands   no change at all okay so first step we have to  download the node.js software this is step one   okay step one we have to download node.js  and then step two we have to install the   Json server and npm package will come along  with the node.js you no need to install this   separately okay so now let us see step one how  to install node.js and then we will see how to   install Json server so we have created a small  document with a screenshot you can just follow   the document as it is and you will able to  install it's very straight order and simple   so first we need to go to this link and this is uh  go to Google first and then type download node.js okay we need to go to Google and type download  node.js and here this is a link you have to click   and this is a official website of node.js software  and here there are multiple versions are available   and if you are working on Windows select  this option and if you're working on Mac   you can just go ahead go this and source code  we don't require if you're working on Mac then   you can select this and it will automatically  download one package here dot pag you can see   here okay and you have to run this package I'm  just canceling this and if you are working on   Mac you will get this dot PKG file and if you're  working on Windows then when you click on this   you will automatically get dot MSA file and this  MSA file is just like an executable file and you   have to install and again when you're downloading  Windows please check your windows 32-bit or 64-bit   okay so we can directly click on this or else  you can just select this option either 32-bit   on 64-bit and if you are working on a Mac just  go with this don't go with the tar or gz file   instead you can just go with this dot phe this  is for MAC Mission okay so this is how fast   you need to download the software so once you  download it you will see a small icon like this   and if you are working on Windows you can see  MSA file or if you are working on Mac you can   see package file okay so dot PKG is a extension  and once you get this file you have to just double   click on it then it will start installation so it  will give the screen and just we need to click on   the next button and then it will show you one  more screen like this just accept terms under   license agreement select this check box and then  click on the next and then go to the next screen   and here it will show you the default location  where exactly your node.js is installed okay   and no need to change anything just let it be the  default location and say click on the next button   and then it will go to another screen and here  by default whatever packages will come along   with the node.js will be listed out here you can  just look at here npm package manager npm node   package manager so this will come along with  the node.js in the older versions We have to   install a different uh as a different component  but nowadays the node.js along with the node.js   the npm is also automatically comes so you can  no need to select anything by default all these   components by default will get along with the  node.js and then click on the next button here   and then here there is a one check box is there  so if it is already selected just uncheck because   we don't need anything because by default when you  install node.js you will get python Visual Studio   build tools all these things by default will be  installed along with the node.js so if you don't   need them so you can just unselect this checkbox  or else if you select this checkbox it will take   more time to install all these components so we  don't need this Python and other things so far so   just until unselect this checkbox no don't select  this and then click on the next button so once you   click on the next button and then you will see the  screen and inside the screen you can see install   button and just click on the install button  so it will take few seconds of time so it will   take a few seconds and then it will complete the  process and then finally you will get the screen   completed the node.js setup which are that's it  you can just click on the finish so this is a   simple installation of node.js software step by  step install is very straightforward very simple   and just download the software first and then go  through the installation process okay so this is   the first thing so once you install this node.js  what is the next thing we have to do is we have to   uh we will get automatically npm package manager  along with the node.js now let us cross check   whether the node.js is properly installed or not  npm is properly installed or marker so for that   what we need to do is as soon as you install this  node.js you need to do one more step here which   is environment variable setup okay so if you are  working on Windows we need to check this otherwise   not required if we just go to the any browser  and right click on this PC go to properties   and here you can see something called  just like Java path we need to also set   node.js path so go to the properties window  properties and here you can see something   called environment variables Advanced system  settings and here go to environment variables   and in this bottom section you can see something  called path variable okay so path variable you   can see and select that path variable and then  click on the editor edit you have to click so once   you click one they read you can see something  here by default you can see these two things   see program file node.js see program file node.js  node underscore module so these two thing entries   should be there in your uh environment variables  so these variables automatically created by the   node.js if not then we have to add them manually  so because this is the node.js path and this is   the location of node.js modules I have given  these parts also in the screenshot you can   just look at this this is just for cross  checking okay so by default node.js will   add these two paths to the environment variable  even if you are working on Mac also by default   these paths will be added you don't need to set  paths separately and this is a confirmation of   installation process so if you set these two  variables properly that means you are node.js   successfully installed so now let us cross  checker how we can cross check whether they   are successful install or not the first thing is  we need to check this variables are created or not   second is what second thing is what we need to  execute some commands through command prompt so we   need to first open the command prompt and if you  are working on Mac you have to open the terminal   and in this command prompt you have to execute  the commands let me just maximize this font okay so here we need to execute one command so  node iPhone version I'm just executing this node   iPhone version so this command will give you  the version number so whatever the node.js we   have installed it will just give you version  number of node.js when you press enter key   so it will give you current version whichever  you have installed it will show you like this   and this is the latest version currently I  have installed and this is the old screen   which I'm showing here okay this is a first  thing 16 15 one this is the current version   of node.js and then we have to check npm  is also successful installed or not for   that we can execute this command  npn The npm Hyphen iPhone version   so this will also give you the version of your  npm so these two commands should be successfully   execute and then you will able to see the version  numbers you can just ignore the warnings okay so   this is the way we can check whether your npm  and node.js and npm successful install or not   you can just check by giving these two commands  Okay so till here we have successfully done   a node.js installation and npm is also comes along  with the node.js and also we have successfully   executed two commands after installation we have  successfully executed this Commander what are the   command node iPhone version and then we have  seen npm hyphen hyphen version so these are   the two commands which I have to execute in the  command window or terminal so that you will get   the version numbers okay so this is a first step  and once you successfully install these two then   we need to install Json server so this is very  much required to run your sample apis or dummy   apis so for that what you can do is to install  Json server we have to execute one command in the   terminal itself so what is the command npm install  iPhone G Json iPhone server so if I execute this   command in the terminal that will automatically  install your Json server so this is the command   okay so from the below command in the command  window or in the terminal if you are working on   Mac this is a command so these are the steps so if  you install this command so npm install iPhone G   Json iPhone server so just copy paste this command  directly if you give any spaces between here so   it will not work again so just copy paste this  command and that will take some time and here   it will finally install the Json server okay so  this is a one of the most important thing so to   create our own apis we have to install these many  softwares so that's the reason at the beginning I   have told you if you want to create our own apis  if you want to create our own apis we have to   install this particular softwares then only we  will able to create our own apis and these are   not related to postman okay if you want to use any  other apis which are already available you don't   need to do all these things but here I just I want  to show you to create our own apis for testing   purpose instead of depending on some external  apis we will create our own apis and we will   test those apis in the postman tool so that's the  reason we have to install these softwares if you   want to create our own apis otherwise not at all  required please remember this point okay creating   our own apis creating our op own apis so this is  the purpose to install this software otherwise   not at all required okay so guys are you clear on  this why we are installing the softwares why it   is required so to create our own EPS to create our  own apis or we can create our own demo APS we need   to install the software okay so for that we have  to do these steps first we need to install node.js   and npm will come along with the node.js then by  using this npm we have to install Json server so   here we use npm command you can just look at the  command itself so why we need this npm because we   need to install Json server next so npm this is  the command install iPhone G Json iPhone server   so this particular command will install Json  server component so once you have this node.js   and PM and Json server now you are ready to create  our own apis we can create our own apis so that is   the next step so to create our own apis so we have  successfully installed this Json server component   okay by using npm we have successfully installed  this Json server component and then now we need   to start creating our own apis so by default you  will get latest versions okay you don't need to   update if you are already installed them so you  can just go with them no need to again install   a new thing okay but if you are completely new  and if you are completely uh newly installing   them so better to download the latest software  and if you already have node.js software on   your machine which is running so then you can  continue with that okay so uh Json server by   default whichever is the latest is available so  that will download and keep it with you so this   will download the latest version always because we  are not specifying any version here so npm install   iphoneg Json server and once you executed this  command it will take some time here and one or   two minutes it will take and then finally uh you  will end up this entire process and that will be   completed your installation installations part  so once the installations are completed now to   run any uh API first we need to have some Json  file which basically contains some data because   any API Works Based on data only right we need  some backend data so if you have data then the   APA will able to get the data will API available  to post the data or retrieve the data or delete   the data so how these operations will be done by  API if you have some data at the back end then it   will work so we need to prepare our own data so  for that we need to create one Json format file   you can have any data Json type of data which  we need to have and the file name should be   anything but the extension should be dot Json is  an extension of the file okay so here I have given   some sample Json data so you can just copy paste  this and create one uh file Json or student.json   currently have three records are there so later I  will go through this Json format what is Json file   how we can create the Json get all these things we  will discuss in detail this is very important but   for now just copy this data as it is and create  one file called students.json and copy this entire   data into the particular file so I already created  let me show you so go to the C type and here   automation practice and Json files and here I have  students.json if I open the file you can see the   same data here So currently three records are  there so this is student data one two and three   records are there so later I'll make you try  to understand this Json file in detail for now   just copy paste everything in this exam uh in  the file and the file name should be dot Json   name can be anything but the extension of the  file should be dot Json okay this is our file   where exactly the data will be maintained even  if you add a new record the new record will be   added to the file and if you delete the record  that record will be deleted from this file and   if you updated any record that decodels updated  inside this file so this is the file which will   maintain as a backend and every operation will  be happen in this particular file okay so you   need to create this Json file and keep that  in anywhere on your location so wherever you   want to create you can just create and have it  with you and that is the next step so once you   have this Json file then we can create our own  API based on this Json files how to create our   own API now just go to the location wherever you  Cooper this Json and then open the command prompt   and currently uh your path is pointing to your  location wherever your Json file is available   you can see I have multiple Json files here  students.json which is created just now and   just go to this location and make sure this file  is present in this location and then here you have   to execute one command called Json iPhone server  because Json server you already installed earlier   by using npm so now once it is completed then Json  server just specify give one space and specify the   Json file that's it when you execute this command  it will start creating our API students API is   up and running now you can see here this is a  home and this is a which contains the resources   okay so once you get this resources and home that  means currently your students apis up and running   currently your student APS up and running suppose  if you close this window then it will stop running   your API okay if you close that window it will  stop running on your it will stop running your   AP but again if you want to start again what you  need to do you need to just go to the location CMD   and again Json iPhone server and then specify the  Json file and it will start your APA once again so   whenever you close this window then your IPA will  stop running so what you need to do now we need to   just minimize this window don't close the window  just minimize the window and once you minimize   this window then how we will know whether this  API is running or not just you can send the URL   so this is the URL so it's TP localhost 3000  slash students so when you open this URL this   will give you list of students which are  available in the database database in the   sense again we have stored the data in the  file now we can see this is the data we got   okay so this is how we can create our own API  suppose if you want to create any other API   just place a different Json file so here I have  a store and you have a employees different Json   files I have so with this Json files we can create  a different type of rest API so different type of   rest apis we can create okay and uh endpoints  uh whatever endpoints which will give you every   AP will not have the same kind of endpoints okay  so currently it is giving one and one here based   on that we will try to do other operators other  operations okay I will show you what are other   operations we can do and this is the way we have  to first create new API okay this is the same way   and if you close this window your IP will stop  running again we have to execute this command   Json iPhone server and the name of the Json file  and tomorrow if you want to create any other API   again same process Json iPhone server and change  the Json file or employees.json stores.json   whichever data you have you can just execute this  command along with this Json so that will start   your API and now currently this AP is running on  my local machine so that's the reason it is giving   localhost to colon 3000 is a port number slash  students so this will give you all the students   data which is currently available in my Json file  okay so this is a step-by-step installation and   creation of your own apis so everything I put  in this document clearly step by step and you   have to go through this document again and do  the steps as it is then you will able to create   your own apis I will provide the Json file also  you no need to create your own I'll upload the   Json file and you can get it from Google Drive  and then create your own API and this particular   API we will use it for our testing for now and  later I will also show you how to create other   apis also along with the students.json  we will also see other apis in future   okay so this is the process of creating our own  apis now can we run this API in the postman tool   yes you can run the same API in the postman tool  okay so please consider this is a demo API so   don't think more about this it is just a dummy API  demo IP which we created in local system just for   our testing purpose okay don't expect more things  from this API just for sending some requests like   get request put request delete request and  these type of requests we can try on this   particular API I will show you what are the URLs  we have to use to perform those operations okay so now we successfully uh created our own API So  currently my APA student debase up and running so   don't close this window if you close this window  your AP will stop running so just you need to   minimize this okay right so now the next thing  is what so once you successfully created your   API we should able to send the request okay so now  through the postman we will try to send different   type of requests like get request put request  post request and delete request let's see how   those requests will work on this particular API  okay so for that what I can do is uh let me show   you the URLs what are the URLs we have to use to  perform those type of requests okay just a second okay so let me show you the URLs how we can access   that API to perform different type  of activities let me close this okay so here I have one small Excel file foreign which contains all the student a related test  cases so I have created Five test cases for five   different type of requests now let's go through  and try to understand that so this is the first   request get request and get a single student data  if you want to get a single student data and this   is a URL which you have to send localhost  comma 3000 slash students so till here this   is the just URL you can just look at this it is  giving the URL also so till here this is actual   resource which we have to use and on top of this  resource we have to add one some more things to   access the data so here you can just look at  this HTTP localhost column 3000 slash today so   till here this is a resource slash one so what  is this one one is representing the student ID   so student ID there's a first field actually  in the data so when you pass student ID here   that will give you student data so this is  student data in the Json format currently we   have ID name location phone number and courses  he is enrolled so this is the content which we   have in the response this is called response  payload we don't need to send any request   payload because it is a get request so we will  get the response like this status code is 200.   now the suppose I want to get all the students  the data so simply you can say URL so slash   students don't specify any student ID and this  will get the all the students information so how   many students we have configured in the Json  file so all the students data we will get in   the form of Json response and 200 is a status  code now if you want to create a new student   so then we have to use this URL and we have to  send post request and again we have to specify the   uh request payload because we are going to  create a new student so when you create a   new student we no need to pass ID okay ID will  automatically generated by the server so this   ID will be automatically generated so one two  three already there so fourth record it will   generate so this keeps incrementing value so only  thing is we have to pass only name location and   phone and courses if you pass this data as part  of request body then we will get the response   like this and 201 is a status code for post  request so the next thing is update student   so update a student so update student we need  to just provide the student ID so which student   we have to update student ID put here put is a  request and which uh what data we want to update   we can specify in the request body and then data  will be updated and then we will get the response   so this is updating student and now finally if  you want to delete the student then again same   URL and whichever the student you want to delete  you can specify the ID here and delete request and   request payload response payload is not required  and the response you will get empty backer so that   data is deleted and 200 is a response code so  these are the details which we have to use to   work with the student apis five types of requests  So currently our student API is running you can   just cross check one second currently it is  running so you can just minimize this window   don't close that window now we are going to send  all this request through post mental okay so we   don't have a patch request every time okay so  patch and put is almost the same I already told   you that many times so don't think about patch  request patch and put so these two requests are   exactly the same the only the difference is  in the patch request we will update only one   single request specific record and in the put  we will update multiple records multiple data   sets so that's the only difference okay and Patch  request most of the times most of the aps will not   support batch request also they will support only  put request if the APA support then only we will   able to send those type of requests if a b is not  supported then we cannot send patch requests okay   so in this API we cannot send patch request we  can send only put request okay and if you want to   update any recorder so now let us try to send this  requests through a postman okay so now I already   created one collection uh with these apis now  let me just import that collection into Postman   tool now let's go to postman and these are HTTP  requests yesterday we have tried now I am going   to import The Collection so the collection all  the student requests I already created and I have   that collection so now I'm importing the existing  collection and in your case you have to create own   collection okay so how to import The Collection  instead I have shown you how to import The   Collection go to this import button and once you  click on import and here we need to upload files   and here student API Postman collection which  is earlier already created and just importing   that open and this say import it so once  you get imported now your student apa's   requests are imported now let me just go to  one by one so first thing is get a student   get to single student record so we need to  just pass the URL as part of the get request   I have also added some tests let me remove  that not required for now okay so this is a   URL for get request so what this URL will do this  will return the single student ID okay so this   will return the single student details based on  the ID so here we have passed ID one is my ID and   then when you send this you will get the single  recorder so you can just look at here ID is one   so now we got the data suppose when you say 2  here so then you will get the second record data is taking some time so whatever the ID have  passed here so we will get the particular recorder okay canceling it let me just check whether it's  running or not or else just keep running one more   time I say Ctrl C and run one more time if you are  facing any delay issues then you can just re-run   the command so that it will restart your API  once again okay and then I provided 2 here let   me run once again yeah so now you can see I got  the second record similarly you can just change   the record ID uh ID value based on that you will  get the data here let me again re change to one say send okay so now we got the first record so  this is how we can extract the single recorder   from the student first we got from the student  this is the API now I already saved it under   collection store and TPS now let's move on to  the next one so suppose if you want to get all   the students data so I have send one more request  and this is the URL and this is the get request   okay and when you click on the send button here  so this will retrieve all the students from the   database now you can see we got three students  in the Json file so all three students we got   so this is one two and three currently we have  only three students so all three students data   we got it from this API request this is  a another request get all students data   suppose I want to create a new student So  currently totally three students which we have   okay now I want to create another student  so how we can create another student   just go to create a new student  and here I have send a post request   okay here we have send a post request and this  is a URL to send the post request according to   the Excel we have to create okay so I'll also  share these files according to the same URLs we   have to copy paste so now go here this is the post  request I am sending when you're sending the post   request we have to specify the body also right so  we need to go to body section here and select the   raw and select the Json from this list and this is  the date I'm sending you don't need to provide the   ID just provide the name location phone number and  then courses and ID will automatically generate   it so when you send the previous request we  got totally three records so id1 id2 then ID3   totally three records which we have so now when  I send the new request which will create the   fourth recorder so the ID will be the four  now let me just execute this send request   now the new record is generated now you can see  here so this is the record which is created with   the id4 okay so no need to have this idea at  the beginning okay not require the order is not   important the data is important all the data is  available always important order is not important   you can just have this beginning or name you  can say here order is not important so which is   generated ID here now again go back and previously  we have a three request now if I send this request   again one more time this time we will get the four  records now we can see fourth record also we got   it from the Json file so this is how we can create  a new record in the Json file by sending the post   request so now I want to update this recorder okay  so currently the name is got location is friends   and some phone number some courses are there so  I want to update this recorder so then we need   to send a put request go to the put request and  this is the request and which record you want to   update just now whatever record I created fourth  record I just want to update then I can say uh   four here four and uh to update the record  we need to specify the what are the details   we want to update again go to the body section  and here you have to specify what are the things   you want to update suppose uh I want to update so  name is same and just I want to update a location   phone number and then uh courses okay location  phone number so location is friends now here   I'm updating as a Germany and phone number is  this one I'm just updating the phone number and   previously the courses are what C C plus  plus now I'm just changing at the C sharp   okay so these are the details I have updated but  even though if you update only few Fields you have   to pass the Complete Payroll okay you cannot avoid  a name and other things so we have to completely   pass so if you are sending a patch request then  you no need to pass the complete thing actually   if it's just only whichever is change is there if  you pass only that change that will allow us if   you send a patch request but this apis currently  is not supporting patch request so we have to send   the complete body and you need to specify what are  the things we have to change here okay so now let   us try to update so I'm sending the request so  now this is a response so previously Germany is   there now it is updated so here location phone  number it should update it's still not updated let me just run one more time Okay so just a moment we have done something wrong I  think we have to do something yeah one second   yeah so earlier it was Ransom okay  now it is updated actually with this   new record it is updated so again if  you go back and uh see here students   data so now it will update it Force  the record is updated now you can see   uh here it is updated so Scott of France  and one two three four five got updated   okay so this is how uh we can send post request  and suppose if you want to delete the request okay   now you can say get go to the get request and send  we already created two records actually so one two   and three and four four and five so totally uh we  created two records four and five also we created   okay so this is the actual updated but again  I have sent request one more time so that it   is created one more record with the same data  okay so now if you want to delete the records   so what you can do is we have to send a delete  request so to send the delete request I have   created one more request called debit student  and whichever record you want to delete just   specify the ID here so I just want to delete  fourth one so click on the send here we don't   need to send any request body so it is not deleted  and fifth one also I want to delete so say 5 here   and then send it then fifth one is also deleted  now you can just get all the students data 4 5 we   have deleted now click on the send here so now we  got only one two three four and five got deleted   so this is how we can send the requests for  student API okay so currently our API is running   okay so currently our API is running but if you  close that window your API will stop running if   I close this window your state eBay will stop  running and whatever the APA request we have   sent through Postman and those requests also will  be shown in this console window in the command   window you can see these are the different type  of requests we have sent through a post mentor   okay so this is how we can send  different type of requests to the API   so now what we have done so we have  successfully created our own API and we   have started our API and then we have successfully  sent different type of request to the student API   okay so clear so for everyone okay so so far  what we have seen is we have created our own API   student API and then we have started running  our API and then we have sent different type   of requests to the student APN we have seen the  different type of responses so I will share this   Excel sheet accordingly can prepare your own  EPs and don't try to import the tech collection   because you will not learn anything but you have  to initially practice this okay to practice this   you have to create your own just create a new  collection MD collection and try to create your   own request but don't try to import I will share  this file anyway but uh don't import that file   okay just use it for reference but you do your  own request yourself and then only you will able   to learn the postman okay so I will also share  this Excel sheet accordingly you can just create   your own request and try to check the response  Okay so we have seen how to create our own API   and how to uh send different type of requests  towards our API and we have seen the responses   fine so here the most important thing is if you  want to validate any request or if you want to   test the API so yesterday we have discussed about  few important components where we need to do some   validations can anyone tell me what are the  test we have to conduct validations what are   the things we need to validate once you send HTTP  request so what are the things we have to validate   suppose I have sent some request here get to  single student and I got some response so on   this particular response what are the things we  have to validate so what are the things we have   to validate so we have to validate the body okay  the content is correct or not we have to check   and then what else we need to check the cookies  are properly creating or not we have to check   this is the cookies information we have to check  and then headers information also we have to check   proper headers are created the header content  values are correctly or not we have to check   right so and then what we have to check we  have to check status code we have to check   and time also we can check size we can check so  different components are there as part of the   response we have to do validations okay so here  to do these validations or to put some validation   points we have to know something called assertions  okay so the APA Postman tool is providing some   kind of assertions by using them we will able to  validate it okay and what are those assertions how   we can write those assets and where we can write  those suggestions that we will see later the first   before that we need to understand something about  the response body this is very very important   so whenever you're sending some request whenever  you're sending some post request we are specifying   the body right and in the Json formatter and  whenever you're getting some response also you got   the response in the Json format so here request  and a response will happen in the Json format   so now before applying some validations or  before doing some validations we need to   First understand what is Json how to write a Json  how we can extract the data from the Json and we   need to also understand about the Json path so  all these things we should be aware of it and   once you understand about the Json then we will  look at how we can perform the different type   of validation so now let us try to understand  the Json that is very very important before   doing all other operations okay what is Json  Json what is the full form of Json JavaScript   JavaScript object notation so this is the full  form of Json J so there is a full form of Json   and what is the use of Json where we will use this  Json so whenever you are communicating between   client and server whenever you are communicating  between the client and server the data will be   communicated through Json format let us say this  is my client and this is my server and the data   communication will happen between these two things  in the Json format sometimes even XML format also   so whenever you are transporting the  data through the network we have to   change the format of data so initially  you may have text files you may have   Excel files right you may have PDF files you  may have HTML files so you can have different   type of data but this data will not be  transported as it is in the same format   so we will convert this entire data into Json  or in XML format and only this format will be   transporting to the network so what is Json means  Json is a JavaScript object notation format this   is a data format we can tell this is a data format  but why we will send data only in this format   why can't we send the data in the text to XLS PDF  HTML format because these are very high weighted   files means what whenever you're transporting  the data it should be low weighted data   okay and moreover the data should able to  encrypt and also decrypt because security is   most important so we should not send the data  in versional formatted so the encryption and   decryption these things are possible only  if you have data in the Json or XML format   and also it is very light weighted software late  weighted data files so when you're transporting   this data in the network it will go very very  faster okay so that's the reason we will prefer   either Json or XML formats to transporting  the data between client and the server   so that is the reason we will use Json or XML  format as part of your request and response   payload when you send your request post request we  will send through Json format when you're getting   the response also we will get the response in the  Json format but when again when compare Json and   XML which one is more preferable is Json will be  preferred okay but XML will be used especially in   the soap type of services but uh rest Services  especially we always we use Json format   okay so the request and a response both will  be happen in the Json format now if you want   to validate the data if you want to validate the  response we need to understand the Json file we   need to understand the Json data and if you are  able to understand the Json data then only we   will able to put some variations on the Json data  that's most important so now we will discuss about   something about Json okay how to create the data  in the Json and how we can specify the data and   what are the different data types are available  what is Json object what is Json array and how we   can extract the Json path how we can identify the  data in the Json so all these things we need to   understand first and then we will able to validate  the Json response okay so now let me just uh share   smart presentation related to the Json and then we  will come back and discuss about validation points and listen carefully this  is a most important topic okay so now let us try to understand Json so what  is Json what is Json path and how to extract the   Json data and so on so first of all what is Json  so just now we understood something about Json   Json is a JavaScript object notation and it is  a Syntax for storing and exchanging the data   so we'll have the data in the form of Json and  we will use it for exchanging the data between   client and the server and it is specially designed  for human readable format we can easily read the   data from the Json it is very easy to understand  okay and Json is basically derived from JavaScript   so similar like X path so from XML language  XPath is derived similarly from JavaScript Json   is derived okay so normally when you're testing  the web application we will have X path right   so we have x x path expat is nothing but what  XML path so this is desired from XML file   similarly we have something called JavaScript  JavaScript is a scripting language just like   XML so from the JavaScript Json is derived so  expat here and here we have a Json path there   are two things will be there okay so now the Json  is a data format we will use the Json format to   transport the data between client and the server  okay so here it has been extended or from the   JavaScript language so which is derived from the  JavaScript language and the file name should be   dot Json whenever you're representing the data  in the Json format that file extension should   be dot Json and uh whenever you some file in the  internet we will have something called media type   and that is application slash suggestion so  wherever you can see this application slash   Json that is representing the Json file that is  always representing the Json format file this is   called media type so every file is having some  media type suppose if it is a text file we will   have application slash txt so like this every  file is having some media type so here if you   have a Json file the media type of Json file  is application slash Json because this is most   important we can see this in the headers part  most of the times and this will says what kind   of data you got as a response how you know that  whether it's Json or XML based on the media type   you will know whether it's a Json or XML okay  so this is a one thing and the next thing is   data type so if you want to represent the data  in the Json we need to know some basic data types   like a number which is used for representing  the data number data string Boolean Boolean   means are true or false null means unknown  value object and array object is nothing but   what again which contains a multiple records  and uh one more important thing is in the Json   we have to represent the data in the form  of key and value page key and a value pairs   so everything is key and value pair so first we  specify the key and corresponding value should   be there so the enter Json the data will be  presented in the form of key and the value   pair key and value pair so number string Boolean  null object and array so we will discuss with the   examples what is an object what is an array and  so on and these are the Json data types and when   you're representing some data in the Json file you  have to uh you no need to specify these data types   but the data which is presented in the Json file  should be part of any of these data types okay   now let me show you some examples here suppose  I want to write some data in the string format   in Json so how we can write in Json whenever  you write some data you have to always start   with the curly brace and the ending curly brace  so inside this we have to specify the data so   this is starting calibration this is ending curly  based between this we can write the data so name   is a key John is a value and what's the data type  of this string whenever you put something in the   double quotations that's a string so you don't  need to write a single line you can also write   in multiple lines also the same thing you can  also write like this if you want to represent a   name of a person you can just curly press closing  curly brace and here name a colon so Name colon   Name colon and a value you can also  specify like this so this is a Json format   this is a Json format so curly press starting  point ending point and whatever data we have that   data we have to specify in the key and value pair  now this is a key name is a key John is a value   and whenever you specify the key that should be in  the double quotations okay key is always included   in double quotations [Music] okay in double  quotations remember this because we do not have   data type of the key but we have a data type of  value so the data types are applicable for only   values not for the keys it can be any key we have  to keep inside the double quotations it can be any   key we can specify in the double quotations okay  so here this is the value because it is a string   we put in the double quotation so okay suppose I  want to store the name of the age of the person   also then I can write a in the double quotations  age age is another key and here the age value is   what a number type so we should not put in the  double quotations so I can give the number like   this so now this is a data about a person name  and age and uh the name is one uh data and age is   another data so these two things we will separate  by specifying the comma by specifying the comma we   will separate so now you can just look at all the  keys should be included in the double quotations   and if values no need to include not all the  values based on the data type you have to   specify suppose if it is string type of data then  we have to include the double quotations if it is   a number type of data we don't need to include  the double quotations so name and age so this is   representation okay so for example uh for example  let's say I want to representing uh let's say this   particular uh person this particular person uh  having some more details like uh he's having uh   phone numbers okay he's having some phone numbers  so then what we can do is we can specify the era   we can specify the earring so for example let's  say phone is a key okay but he is having two   phone numbers he's having two phone numbers so  then how we can specify those two phone numbers   if we want to specify multiple inputs for one  variable we have to keep in the square bracket   that is called as a Json array now what we can do  now in the bracket you have to specify suppose one   two three four five is one phone number and there  is another phone number so if you have a multiple   sets of data for one variable then you can specify  like this okay so this is a way we need to specify   and this is called as what array this is called as  a array which is contains a multiple records again   the phone number is a number data we don't need  to keep in the double quotations okay number data   we don't need to keep in the double quotations  and if you want to store them as a string then   we need to keep in the double quotations and  for example this is he is also having one more   field called status for example okay status then  uh status value is a Boolean let's say Boolean   value so if it is a Boolean it should be either  true or false so here I can say either true or I   can say either false and how we can represent the  Boolean data here again Boolean data not require   the quotations only the stringed type of data  we need a quotations okay only staying a type   of data we need a quotations all other data we  don't need any quotations okay so true is not a   number not a string that is a representation okay  true and false because Boolean values are accepted   only true or False only two values are accepted  so other values are not accepted so that's the   reason we have to say only true or false without  quotations without quotations and if you don't   know the value then you can simply say null okay  for example this person is having uh let us say   he is a let us assume this is my first name of  the person now the second name second name is   don't know the second name so then what you can  say second name is null I can put second name   is null null is nothing but what unknown value  null is nothing but unknown value so later if   you want to update this value you can update here  if you want so the first name second name and this   is the string data type this is the null this is  the number data type this is the Json array array   means what with for one variable one key can have  multiple values one key can have multiple values   okay so this is a phone number and this  is a status Boolean value true or false   so this is how we can represent the Json data  or the data we can represent in the Json format   okay now this is all one object we can consider  this all is one single object one Json object   because which contains multiple fields and  values this is one Json object okay now let   me show you a few more things so we have seen some  examples sometimes you can see like this okay this   is a student is a object and which contains a  different type of data this is one record this   is another recorder okay so I will show you  a different things here uh now go back again   okay so for example uh let us uh try to store  the student data okay so I want to represent   the student's data I want to represent the  student's data okay I want to represent   students data so I can write one student subject  student object starting curly Place ending early   days okay okay now I have it let's say I have  a two students every student is having ID name   and some designation okay so ID name let me  take one more field ID name or something or   some first name okay so name is already there  ID name let me take something called designation   or a grade let me put the points here  every student is having their ID Sid   okay and s name and grade okay these  are the three values every student is   having now I want to store two students  data in the Json format I want to store   two students data in the Json format so  now how we can do that I can say students   okay starting and representing early place and  here first student so two students I have told   you right two students are nothing but what do  arrays we have to take okay so two students in   the sense two arrays we have to take so how to  representing the uh arrays now we can represent   like this colon and you can just look at this  students colon and this is a starting point this   is the ending point because this is our array so  we can just put like this so starting curly brace   ending curly brace this is actual Json object  inside this we have to create a student's data   so here you can say students is my key students is  my key and there are so many students are there if   you have multiple students we have to use an array  concept right so this is my object from here to   here Json format starting point ending pointer  so how many students or data I want to store   multiple students data I've understood so now  students is my key and which contains the multiple   values what are those values student one value  okay student one values student two values student   three value and so on but again every student is  having Sid name and grader student one is having   a study name and create student two is also having  Sid name and grade student degree is also having   Sid name and grade but how we can represent that  so basically students means what multiple students   so I put one array concept here let's put the  next line here this is a bigger I have taken now   inside this I have to store multiple students data  multiple students data now how we can represent   the data now student one data I want to represent  so how to represent the student one data here   curly brace curly brace student one data right so  I can say here yes ID first Sid equal to Sid is a   number let's say one zero one comma S8 is a key so  we need to put in the double quotations now in the   second thing what is the next field yes name I say  yes name so s name is a Stringer so I can say John   now what's the next value grade grade so I can say  grade and this is also a string type so I can say   grade equal to EA and done so this is a record of  First Student so recorder first student is done   now comma Now the second records for second record  student what we need to so Square second yeah   comma is missing here yes every key and value pair  should be separated with comma for the last record   we don't need to put the comma so this is end this  is a first record of First Student now same thing   we have to repeat for the second student second  student so this is a record of the second student   see now student ID is 102 and I can say  Kim is a student name is my student name and the gradius let us say B now this is a data  of the second student sorry guys it is not equal   to actually this is a colon sorry okay this is  not equal to this is the colon we should not   put equal to we should put colon following  Java syntax sorry so this should be colon   okay so this is a representation fine  so these are the values and the keys so we do not have single code here all our double  quotes even as a single character or multiple   characters everything should be in the double  quotes now similarly we need to add student three   student three data what we should do now comma  and copy this entire thing and place it over here   so now student number three and uh name you can  just pass some name here I say Scott and then   grade is C okay now if I just look at this data  so from here to here this completely one Json   data and which contains a number of students data  so what we have to store multiple students data   so that it should be array and inside array we  have created multiples during this so this is one   student data and this is another type of student  data and this is another type of student data so   for the last record we don't need to use come so  first student second student and a third student   okay and this is one object Json object  this is one object this is one object   so now the Json array contains the Json objects  so this is how we can create a Json file based   on the data we can create our own Json file okay  so at least this much we have to understand about   the Json and once you understand this then we  can validate the data also so whether aside   is one zero one correct or not or grade is b  or not and here the third student his name is   caught or not so these things we can validate  in the postman these things we can validate   but before validating we have to understand the  structure of Json that's most important thing   okay so this is the most important thing we need  to validate so because as part of the response   body or response we have to validate the body also  right response data so normally the response data   in the Json format if the response data in the  Json format so we have to understand what is main   node what is an array whether it's Json object  or not so we need to parse this data properly and   then we will understand this then only we will  put some validation points on the response data   that's the most important okay so now I'll share  this presentation which is having same thing and   the comparison between JS and XML sometimes  you will get response in the XML format also   and when you again compare these things uh  advantages and disadvantages are there for both   Json and XML and Json is basically a simple to  read and write we can easily understand Json and   we can easily write our own Json but XML is lesser  simple as compared to Json and uh Json in the Json   format we will it support array concept but in XML  array concept is not there it doesn't support and   when you read the data from Json XML most of the  times we feel easiness when you read Json file it   is more easier than XML file and the data types  the Json will support only texture number types   and XML support other types also like text  number images charts graphs so other data   types also supported in XML file so this  is a basic difference between Json and xml5   okay now here you have given same example so this  is a Json examples of employee data and you have   created one array which contains employee details  name and email and the same data is represented   in the form of XML formatter so as of now XML  is not important I will discuss a few examples   about XML uh after few sessions okay for now  we will completely focus on Json format okay   and then Json object a Json array so what is  the Json object this is a Json object employee   which contains a name salary marriage so this is  the Json object just in our example so this is   a Json object this is one object this is another  object object in a sense which contains a multiple   key value pairs so you need to understand  that object is nothing but what Json object   is nothing but what which contains the multiple  key and a value page that is called Json object   Json object is nothing but which contains a  multiple key value page so this is one object this   is one object this is one object and uh the array  can have normal values primitive types or objects   now if I can never say this array of objects  can we say this is array of objects or not   yes or no so if you write this let's  say I have written something like this   okay so this is my Json I say students  okay I can say students okay and here   or in the students I can say here I put 100 200  and 300. now can you see the difference between   the above and this one so here students  is just a array just an array the students   is a key which contains the only primitive  values which contains only primitive values   but here students is an array students is a  array which contains a primitive values but   here students is an array which contains a objects  which contains a objects that is the difference so   now era contains a primitive values right if you  want to store the names only names then what you   can do you can put here let's say a comma B comma  C so these are also primitive types so these are   also premature so now this array contains only  number this array contains only strings now   this array contains objection Json objects clear  everyone so far so if you understand this much   that is more than enough from Json so we'll able  to put some variations on the Json okay so here   I have given more number of examples I will share  this presentation later you guys can go through it   and try to understand and whatever explanation  I have given which is all related to this one   and we have understood the basic examples here we  understood what is Json object and also we have   understood Json array so both we have understood  so Json array means what this is a Json array so   the array contains all the strings array contains  all the numbers array contains only Boolean values   and here the array contains the objects employees  are a variable which contains a multiple object   this is an array starting point and ending  point and which contains a objects Json objects   okay so just need to understand so this is a  complete structure of Json and I have given each   and everything is a different part keys and Value  Place and uh to capture the Json or to validate   the Json we need to understand something about  Json path okay if you want to violate any data we   have to write something called Json path now what  is the Json path so that we need to understand   so for example here let's take our example  now I want to extract the the s name of the   first student I want to extract name of the  first student I want to extract the name   of the first student how to extract from  this Json let's say this is my Json file so let me just put it here okay so this is my Json  file from here to here I want to extract this one   okay so to extract this one we have to write a  Json path we have something called Json path so   by using Json path we will able to extract the  data from the Json file suppose how to write the   Json path for this particular field to write the  Json path for this particular field we have to   start from the beginning so students is an array  right first we need to write students students   okay in the students we have multiple objects  this first object second object third object   now in which object this s name is present in the  first object so students of one students of one   okay and we index will start from zero so  we have to say zero because array index will   start from zero only so students of 1 0 Dot in  this which will be I want to access the second   field Beyond accept which what is that s name so  here we have to say yes name okay so this is the   Json path which is representing yes name this  is a Json path which is representing yes name   okay now so array indexes start from zero guys  okay this is 0 this is a one and this is a two   we need to cancel like this okay yes order is not  important okay suppose if this record is present   here if this record is present here now I want  to extract okay now I want to extract this s name   then what we need to again same Json path now this  time it will extract this as name not this one so   in which order the data is presented in the Json  in the same order we have to write a Json path   okay back to here we are specifying right order is  nothing but what I'm not talking about this order   objects I'm talking about the internal Fields if  the grade is present in the first place no problem   if the name is present in the next place no  problem why because we are specifying the key here   okay we are specifying the key  here okay now if I write Json path   like this which value it will give you  which value it will extract now tell me   so students of 0 dot name I have given so let us  assume this is a place it here this will be placed   here so now tell me uh if you place here so what  is the value you will get when you put like this   let me just decrease the font okay  so that you are able to see that okay so now when I say students of zero dot name  what is the value you will get here John John   right perfect now uh tell me I want to capture the  Sid one zero three I want to capture now tell me   what is the how to write a Json path yes id103  I want to capture sid103 so what's the Json path   first you need to go to students of  students of what is an index 2 is an   index inside the two we have Sid so I need  to say yes sorry so this will return 1 0 3   okay just by writing Json path we will able to  extract the data available to extract the data   so if it is a very simple and very basic Json  file we will able to create our own Json path   but sometimes your Json file having complex  data there is a lot of data is available it's   very very complex but in those cases it is very  difficult to write a Json path so what we need   to do now we need to take the help of some tools  to generate the Json path okay so what are those   tools we have a two tools are available so  one is what Json Pathfinder and Json path   Json Pathfinder and Json path you can use these  two applications now let me just open this so how to use Json Pathfinder so let's open this  website jsonpathfinder.com so here first of all   we need to place our Json so let me place our  Json file so I'll take student.json whatever we   created and copy it here okay this is my Json  file Json data now if I just look at here it   will automatically generated Json paths in the  right side window if you expand the students it   will automatically generated XML path so this is a  data representation now you can see uh if you want   to get the uh if you want to get the Json path of  this phone number okay phone one one six five four   nine is there so this is the phone number I want  to get the Json path so how we will get it now   and where it is there we need to go to this one  so zero first record one record one two three   records are there so zero one two because  index start from zero and now where we need   to go to get this one third one so we need to  expand the second one so what is the field name   here is phone number so now click on the phone  number here so it will automatically generate it   Json path so X is just representation of root  node you can just ignore it so we need to consider   from here students of two DOT phone so this is a  Json path so this will help us to automatically   generate Json path if you have a complex Json file  or if you have a data which is very complex so   in those cases we can take the help of this tool  and which will automatically generated Json path   whichever field we have identified as you can see  as soon as I have identified as soon as I click   on the particular field this is automatically  generating the Json path and by using this Json   path we will able to extract the particular data  and then we will apply some validation whether the   data is correct or not suppose I want to check  this name is John or not so first we need to   write a Json path and this name should be equal to  John that is our validation and similarly I want   to verify the four number of the first student so  I can just click on it this is a Json path so by   using this Json path extract the data and now the  data is equal to that phone number or not we need   to verify so first we need to extract the data  from this Json then compare that data with our   expected data so that's how we need to evaluate  the Json response so to validate the Json   response it is very very important to get the  Json path okay if we don't know the Json path   we cannot extract the data from the Json we  cannot validate it this is the one tool very   very useful too which is having and there is  one more tool called jsonpath.com jsonpath.com okay so this is also very very helpful so here we  can check that our Json path is correctly written   or not so in the first tool it will automatically  generated the Json path but in this whatever the   Json path we already generated which is correctly  identifying the value or not that we can test it   here okay for example let us take the same Json  data here also okay so now what I will do is here   I will generate one Json path some particular  field let us say ID to Second record uh name   is Kim right so you can just go to Second record  second record second is nothing but one here so   name is a Kim so this is a Json path so which is  exactly identifying the Kim but this particular   Json path is correctly extracting the value Kim or  not how we can check it here here it is fine it is   just generating the Json part but how we will know  whether it is exactly pointing to the same value   or not Kim it is returning or not simply we have  to copy this and go to this another tool and then   paste it over here remove this and paste it over  here and once you paste it here you can see the   value here it is exactly written in Kim or not  yes it is returning chemo so this is how we can   validate our own Json path and if you are creating  your own Json path how we will know whether it's   correctly written or not simply you can paste your  Json path here Json data here and then it will   return this your Json path will exactly return  the data here whichever it is matching in the Json   and both are very very useful in the first  one here we can generate our own Json file   Json path based on the Json and the second  is for what whatever Json path we generated   which is correctly extracting the data from  the Json or not and that we can check it   here okay so this is how suppose I want to  extract this one so python I want to extract   okay so this is a python I want to extract  now how to write a Json file here Json path how to write a Json path please tell me now I want  to extract this python this is the one I want to   extract so how to write a Json path where we need  to go students of one because that is there in the   second record so we need to go to index one inside  this courses is there right courses dot courses   okay dot courses now if you just leave here it  is returning two things so Python and RPM now I   want to access only python the first one I want to  access again the courses is what array courses is   what array so if you want to extract python what  is an index we have to specify one we have 0 we   have to specify so now you can see this is a Json  path which is extracted python from our Json data   so we have to practice this which is very very  important okay so we need to understand the Json   format and then how to write the Json path how  it is going to extract the data from the Json   and once you extracted this data then we can  validate it whether exactly it is python or not   okay so for that we need to add some validation  point we will use something called assertion   inside the postman those options are available  but before that we need to capture we need to   understand Json how to analyze the Json data and  how we can extract the Json data how to write the   Json path and where exactly we can check Json  path is correct or not so all these things we   have to know at the beginning level and then we  will able to do some validations on the Json data   okay so I'll share this presentation just go  through this and try to understand Json about   Json and then in the next session we will see how  we can perform the different type of validations   and not only Json response body and we also  do other type of validations like status code   okay and uh then we will also validate time and  uh then we will also validate headers cookies   and everything we will able to validate them  but most important thing is data okay data we   have to valid whether we are getting right  data or not that's most important and then   we'll able to validate the rest of the things  okay so in the next session we will see how we   can validate the response so once you get  the response like this how we can validate   this response how we can validate the fields  how we can validate cookies headers and how we   can put the different type of validation points  so these things we will see in the next session   okay so I'll stop here for today's session  we will continue in the tomorrow session
Info
Channel: SDET- QA
Views: 302,855
Rating: undefined out of 5
Keywords: Python, Selenium with Python, Selenium webdriver, Automation, Testing tools, Selenium tutorials, Python tutorials, Manual testing, SDET, Java, selenium with java, big data, hadoop, web services, postman, soapui, rest assured, big data testing, hadoop testing, ETL testing, SQL, Programming, Software Testing material, selenium videos, python videos, automation vidios, jira, jmeter, performance testing, functional testing, QA, QC, Agile testing, SDLC, Automation Step by Step, restapi
Id: tnpqR7Ar-BQ
Channel Id: undefined
Length: 81min 24sec (4884 seconds)
Published: Fri Nov 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.