#4: Cypress API Automation - API Chaining (POST then GET)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is snapini here welcome back to naveed automation labs so in the previous video we have seen the post call and we were running it from the hitting it from cyprus and we can see that here you can see that we are capturing the data and sending this particular body request along with the boast call and we were getting couple of things that uh 201 and then these are the things that we were verifying now the actual thing is that what if the developers they have hard-coded the value what is the guarantee that the kind of data that you have created this user that you have created exactly same user if we try to fetch with the get call the same data is coming or not so we need one a unique identifier for example let's see if you're calling this particular api with the post call and this 1494 let's say i'm just calling it again let me just pass the body once again some different body i'm passing 90 here and this is the email id i'm passing and this is the for example let's see two two five four response we are getting id is this and the user got created now same user i'll be using with my get call so i'll simply come over here and let's see i'll be using with the get call here so i'll just copy this url and paste it here so this time is saying okay yeah this email id this 90 that you have created test automation mail active so i want to call the get api once again after my post call but what we have to do when we call the post call first time this is the id i have to capture at the runtime from the response and the same id i have to use in my next api call but the test should be same it should not you have to create a separate test block or separate it block you have to create no with the same it block with the same test case it should be a single flow create the user and get the user so how will you do this now this is called you can say simple correlation also so what we have to do we just go to here and then here what exactly i can do it that uh whatever the response that we have captured and we have verified with the for the post call i'm going to write one more then over here so we can write dot then here and in this particular then i'll just capture the response once again right this particular response i'm going to capture it and the same risk from the same response i can capture the id right so i can maintain one constant here this is my user id which is equal to what from the response dot data dot i simply write response dot body actually dot a data dot id so whatever the data that we are fetching over here see this particular data go to id and capture whatever the id got created like c2254 whatever at the runtime it will be a new number in that case you just capture this particular a value and then i just print it over here with the cy.log also so i'll write that okay fine this is my user id i'll write the user ids plus user id and this and now the same user id i can use it for the next call now next call is what next call is again i'll be writing cy dot request method i'll be using it and this will be this will be my get call so let me just close the request and then same thing i have to define it over here that what is the method the method type is uh get call so i'll be writing this is my get call comma then do you have any uh url so yes i have this particular url so exact same url and then the header i'll be using it so let's uh pass the url but this time the url will be what v1 uses and we have to slash and we have to pass the user id user id that we have already captured so just simple right append over here plus user id so my api will be what get call v1 user and then forward slash whatever the numeric user id we will be getting it add the authentication token as an header once again and then do what and after that this is my get call is completed so i'll be so let's see this is my get call is done up to here after that i'll be writing dot then once again and then i want to verify couple of things so in this particular then i'll be writing one more response here response of what response of this c by dot request this is my next call guys right so i'll just write it for you this is my this is the second call the call is get user once again okay like that so and this was my first call i'll be writing it over here this is my create user so this was my post call and this is my get call okay now then what then first of all that you just validate same thing expect response dot status it should be 200 this time and then do what and then you verify a couple of things here so let's see i'm going to verify that whatever the id first of all i want to verify the id data dot id should be equal to what it should be equal to the same user id that you have already captured and then you can check the payload name and the status also you can capture it the same user information you should get it here with the name and the status or email id let's check the email id also perfect so let's see it is working or not so i'll repeat quickly first of all i'm doing what i'm creating a post call and sending the request from this particular response i'm validating it and again i'm creating one more then block over here again i'm capturing the response now this response i'm using it for to capture the id okay so this is again the json path i'm using it response dot body dot data dot id printing it on the console and then again hitting the get call with the url changed now and in the url i'm using the user id i'll append over here and then again i'm using a then so that i can variate that okay yes whatever the same user id we are capturing it or not with the same name or everything that is coming from your payload payload means the fixture payload that we have already seen in the last video perfect so let's see it is working or not so i'll just uh open cyprus and let's call this api post user.js so this should be an end-to-end scenario wise that's a perfect validation see awesome nice see this is my first request with the post call you can see that v1 user all the validation got passed this is the body and the id is 2266 and then see a user id is two to six is whatever c by dot log that we were printing it right same thing you can check it over here see c by dot log user id is 2266 and then appending it over here in the get call and then checking all the responses from there checking all the expected uh assertions over here like that so this is absolutely working fine so it's important to add the get call also at the end how will you verify that the user got created successfully or you do one thing you just make the database connection and then check it over there but what if your database connection is not allowed and then better you call get api and then check the same user you are getting it or not so this should be an end to end same thing you have to do it with the delete also same thing you have to do it with the put also and the patch also you will see those things in the upcoming sessions okay that's all for this particular video guys i hope you liked it please subscribe to the channel if you're liking cyprus with api automation and let me know if you have any issues i'll see the next video till then take care and god bless you all
Info
Channel: Naveen AutomationLabs
Views: 3,012
Rating: undefined out of 5
Keywords: Create User - POST REST CALL, cypress api, cypress api testing, cypress api automation, cypress api mocking, cypress installation, cypress installation on windows, how to install cypress in visual studio code, how to install cypress on windows 10, cypress by naveen, cypress vs selenium, naveen automation labs, Cypress API Automation - GET Call, API Chaining (POST then GET), API CHAINING in cypress, cypress chaining get, cypress chaining assertions, cypress chaining should
Id: Inz3aDNqX38
Channel Id: undefined
Length: 7min 33sec (453 seconds)
Published: Mon Jul 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.