POSTMAN BEGINNER TUTORIAL 15 💡 Data Driven Testing | How to get data from CSV, JSON file

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this session on postman beginner tutorial and today we are going to learn how can you do data-driven testing or how can we get your data from a CSV file or a JSON file in postman so we are going to go very basic step-by-step and we will learn how do we get the data from a CSV file how do we get the data from a JSON file how can we run the data-driven API requests and finally we will see how can we run our data-driven tests in postman towards the end of this session we will also look at some useful tips so let's get started and let me go to my postman and the first thing I will do is I will create a sample request here so for that I can go to Google and search for a simple REST API request and if I go here I'll get some options and this option req are yes this has some good API so I will go here and here you can get some sample API is for testing so I'm going to go with this post register successful I will click here and it gives me the endpoint and the body of the request so I will copy this URL and go to my notepad and paste it here and then I will also copy the endpoint from here and go back to my notepad and paste it here and I will copy the body as well from here and this is I have to give in to my request in postman so let me go to my postman now and you can click on this new button from here and create a request also you can just go to a new tab from here and start adding your request so I will go here and I will say this is post give the URL here and then I have to click on this body go to raw and copy the body from here and give it here and that's it I can click on send and see if my is fine and this is arid missing email or username so it is not able to identify the body so maybe we have to keep the headers so I will go to the header section and say content type the value should be application JSON and now if I go to the body you can see this is now formatted so now this should work fine I will click send and yes I am getting back the token so this is working fine the other thing that I have observed is if you give some if you append something in the endpoint so let's say I say this is three broad environment and now if I run this again you can see in the response we get back the email password ID and the created date which is good for our assertions and validation so we will go with this and now I can add it to the collection so in this collection one I have get and post folder I will create a new folder I will say add folder and I can say this is post true and I will say create and now I can click on this Save button from here and I will give this name as register user and go to collection one and inside post two I will save this so if you go to now post two you can see your request is now saved here now we have our request ready and now we have to refer variables into our request so what I can do is some of the values I can refer from variables so let us say I want to refer this endpoint from a variable I will copy this and go to my notepad and paste it here and then let us say this email as well I won't put over it from a variable I will copy this and paste it here and similarly this password so I will copy this again and go to my notepad and guests here so I won't these values to be referred from a variable so I can give any variable name I will say this is as endpoint this is the email and this is the password okay so now I have to create these variables and we have already learned in our earlier sessions that there are three locations where you can create the variables first one is the collection so you can go to your collection click on these three dots and go to edit and here you will find a subset for variables so you can create variables at the collection level also if you go to this gear icon here here you can go to Global's so you can create the variables at the global level these are global variables and also you can create a new environment so you can say ahead create a new environment and then start creating your variables here so what I am going to do is I will go to Global's and I will start creating the variables here so we have endpoint and we have email and password and I will get the values so this is the value for email this is the value for endpoint let me grab it here and then this is the value for email and this is the value for password so I have given all these values here and I can save and close this and now I have to refer these values here so the syntax is inside double curly braces I can give my variables similarly for email and password and I will save and run and yes this is giving me the result so that means our variables are created properly and are being referred properly now let us go to the collection runner so I will go to this collection and if you go to this forward arrow and say run we have this collection runner so you can select the collection here so I will select collection one and post to folder which has our request and here I will just say run post two and this is running fine now here in your collection runner you will see there is a section or a field called data and you can select a data file so now we will come to our topic how can we refer these variables from a data file so we will see both CSV and JSON file so the first thing I have to do is I will create a CSV file I will go to my desktop or any location and create a text document and I can name it as data 1 and I can make the extension as CSV and I have the data 1 dot CSV created I will open this and now I will just add those three values here so we had endpoint and email and password so let me also add the values here for endpoint we have this value for email we have this and for password you will give this value pistol so we have given our values here let us also create a second set of data so what I will do is the endpoint will be the same and email I can say a curve at gmail.com and pass what I will say automation and let us see if this runs this I will save this and close and go to my collection runner and here now I can select the file I will say select File and select my data 1 dot CSV and say Oh and it has already taken the type of the file which is text CSV and this very good featured in postman is you can actually preview so if you click on preview it shows your data and formatting as well now here there is some problem the formatting is not proper so let me go back to my CSV file and let me try to open it with a notepad and yes the problem is there are no commas so CSV means comma separated values so I have to give the commas here which was somehow missing so let me give all these commas after every value and save this and close this go back to my collection dinner I will delete this and select the file again and open and now let us go to preview and now yes everything is coming properly formatted and now I can just run it and you can see it has done two times because we had two data and if you go to the first request and go to the request body you can see it has taken our first row from here and then if you go to the second request and go to the request body you can see it has taken data from our second row so this is working fine let us also see how do you use a JSON file so I will create again a new text file and say this is data too and the extension is dot JSON and now I have to add the values here so in a JSON file the syntaxes you will start with our open square bracket and the closing square bracket and inside these square brackets you will add your data inside curly brackets so I will give open and close curly brackets and now I can start giving my data so I have endpoint and this should come into quotes and at Colin and the value so the value of the endpoint is this one so I will copy it from here and then paste it and the courts end then comma and then the second one so I have email and I can get actually give anything right so let us say this is ABC dot at gmail.com , and then I have to give a password and I will say this is one two three and that's it now if you have to create a new data set or a new like a new row in the CSV in JSON we just copy this and create a new object so this is the new object so and the new block and here again you can give something so this let us say this is d EF and this is four five six so now this is created the other a useful tip is you should always validate whether the formatting is correct so you can copy this end go to your browser and search for any JSON beautifier or json editor and go here and copy this and beautify and yes everything is fine so in case there will be any issue for example you forgot this course here and then you will say beautify it will give you the error so you can you can be sure that you know your JSON is properly formatted okay so our JSON is formatted properly so I will just save this and close go to my postman and go to collection runner select my request folder here and what I'm going to do here is I will select the JSON file this time so this is data two dot JSON I will say open and in case of JSON sometimes it does not recognize the file type so I will manually select application JSON from here and say preview and yes it is coming formatted properly and I will say run and yes the first run it has taken the values from the first object in the second run it has taken values from the second object so this is running fine now something very important is this is all fine for getting the data from a data file in APA request however if you want to get data from our external data file in our tests or in a pre request script this will not work exactly what we have seen until now so for example if I go to my request register user and I will go to the tests and here I can start creating a test so I say there is this is a test and I will name the test as validate body contains email and equals to I will say response body dot s and here I have to give the value right so for example I give ABC dot G mail.com however I cannot refer the variables directly like this here so if I say email it will not be taken from the data file let me just shorten the name of that test so that I get everything on a single line and yes so for example here to get the data from the data file what I have to do is I have to say data dot in the name of the variable so which is email in our case and the other way of using this is I will create other tests and this will be for to check contains password and here you can also say data and inside square brackets and inside the course you can give the name of the variable so this will be now referred from the data file so it will refer the email from data file and it will refer the password from data file so now you can save this and let me go back to my collection runner and here I will go to my collection one go to post two and here you can also select some environment and then I will select my file which is theta 1 dot CSV and if I preview you can see in the first run the email is set niet life and password this pistol in the second run we have this email and this password here so I will close this and I will say run post and you can see it has run - I trations and both of these are now successful and we have contains email and contains password test successful for the first iteration and for the second one also you can validate in the second iteration if you go to request body you can see this was the data went into the request and if I see the response body you can again see this was the response that came back and our tests has validated and for test fast and zero field so this is how you can refer the data from the data files also one useful tip is you can use these variables from the data file wherever you can use the environment variables so this is something that you should always remember that data variables can be used at any location where environment variables can be used except in pre request and test scripts which we already saw that in case of a pre request or test scripts you have to give the format like this and same goes with the pre request script as well so in this session we learnt how do we get data from an external file in our AP requests and our test scripts I hope this session was useful for you if you liked the session please hit the like button and share with others and don't forget to subscribe to this channel and get notified on all the new videos that I will create for automation testing them up since CI I will meet you soon thank you for watching
Info
Channel: Automation Step by Step
Views: 166,466
Rating: 4.9291859 out of 5
Keywords: postman data driven api testing, postman how to get data from csv, postman how to get data from json, postman how to refer data from external files, postman how to refer data from csv file, how to refer data from json file, how to use data variables, how to refer data from csv file in test script, how to create data driven tests, postman beginner tutorials, postman tutorials for beginners, postman api testing tutorials, How to Run data-driven API Requests
Id: BzHsDihOlfY
Channel Id: undefined
Length: 17min 13sec (1033 seconds)
Published: Sun Mar 11 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.