#10 - DataTable (asLists) in Cucumber BDD (Part 1) - Latest 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is naveen here welcome back to naveen automation apps so guys today we are going to talk about what is a data table in cucumber feature file and how to implement that a very important feature and very easy feature and what you can do that a particular step you can parameterize in your feature file for example let's say i want to do a couple of user registrations with multiple users so if i write a typical feature file over here so let me create a feature file let's see right click on it go to a file over here and let's see i'm going to give that is user or i would say simple registration dot feature in this particular registration dot feature let me remove this and i simply write a feature over here that is my feature name is let's say user registration and i'm going to create a scenario over here that is scenario name is a simple write let's see user registration with and then i'm gonna write a couple of steps over here i simply write a given and let's see user is on a registration page and i'm simply writing when user enters let's see on a registration page we have first name last name email id phone number password address all these things we have to write right so if you write multiple steps for each and every a field then it will be a lengthy scenario or many steps we have to write for each and every field over here for example let's see if you're writing user enter enters last name again i'm writing let's see when user enters like that steps we have to write let's see user enters a phone number so this is not that a standard format we can use one a data table format over here provided by giving birth and i simply write when let's see user enters and then i'm going to give some a data over here in the pipe separated form so let's see i'll put a pipe over here the straight line and i said okay yeah this is my first name let's see my last name is something automation and then i'm writing my email identity nav at the gmail.com and let's see my phone number something like this and then pipe over here and let's see in which city let's see i'm writing panda over here likewise i can create multiple set of data same thing let's say i'm going to create for a different user the next user is tom for tom let's see the last name is uh tom peter and i'm writing it's email id tom gmail.com phone number something like this and then city is let's see london put a pipe over here at the end also and i'm going to create one more user let's see and then city is let's see san francisco like that right and then i simply write my final step over here then successful simple like that so these are the steps let's see that i have written now i have to write what i have to write a feature file a definition file over here so i'm going to create a step definition file you right click on it and go to class and simple i'm gonna write let's see this is my user registration or steps click on finish okay and then what i'm gonna do that let me do one thing let me just update this particular project first sometime my feature file is not flat right now it is betting flagged and i'm gonna run this particular registration feature so that i can get all the step definition methods over here and then i'll be using those methods so simple run configuration and then i simply write that browse that particular registration dot feature in this particular project you can practice click on apply and click on run when you run it you will see that on the console that all these steps are missing so i'm going to copy these steps from here and i'll go to my step definition that is a user registration steps.java and then paste it over here and if you notice let me import all the annotations and if you notice this thing that this is quite normal that's fine so let me simply remove that let me remove that your registration should be successful the last step also but if you see this third second step it's saying user enters following user details it means the data is coming in the form of data table it means the parameter is coming in the form of data table and this data table class is actually coming from where from the cucumber library so let me remove this commenting part we don't need that and then you can ignore this particular part also from here actually you have to just pass the data table object over here and data table you can import from cucumber so import from cucumber over here like that simple so when the second step will be executed the data will be coming in this particular data table so for the first step let's see i quickly write system.out.println i'm not writing any selenium code as of now i simply say that user is on or let's see i simply write user navigates registration page and then some system dot ordered pin talent i'll be writing over here like this and now i want to do multiple registration it means the data is coming whatever data that you have written in this particular feature file this entire data will be given to to the second step to this particular data table object and from this particular object you can give any name you can give a table also or data table whatever the name you want to give or you can write a user registration table also so let it be data table only and then i'm writing data table dot there is a method as a list method you have to use that okay not as list and then what kind of list you want to get i want to get a string type of list because data is available in a string so i simply write string dot class and this as list method will return what it will return one list of list of object so i simply write it will return one list of list of what what type of data we have we have a string type of data and then i'll be creating a list over here let's see this is my user list is equal to this and then we have to import this particular list from java dot the util package so let me do one thing okay and then let's put a string over here like that all right so we have to import this particular list from java.util package now what i'm going to do i simply create a for loop over here so that we can traverse this particular list because list is order based and i simply write user list okay in this particular user list so what type of data we have in this particular list so i simply write that okay from this particular list of a string and then e in which list in this particular user list and then what do you want to print system.org print the value of e over here it means print each and every list so in the first iteration i will be getting the first list set of data that is naveen automation second data tom peter and then for lisa we will be getting in the third row simple guys so you in my for each loop i have to use what type of data we have we have a type of data as list of a string not only string we have list of a string e and in this particular list i'll be getting it so let's run it and let's see what happens so i'm going to run this particular registration.feature once again run configuration and let's see it is working or not so here you can see that yeah it's absolutely working fine and you can see that this is my scenario and this is user navigates to registration page given user is on the registration page and then we are entering these three values over here so can you see that it's printing all the values one by one naveen tom and lisa and then this is my step name your registration should be successful and this is the last step that then step user registration should be successful and this is the print statement we are printing it one scenario three steps are absolutely working fine so like this you can use the concept of a data table in kicker now whenever you want to fill the data let's see on registration page some user details page so let's see you want to do some login in that case or the form filling submission in that case you can use a data table over here so this is not the example keyword this is the data table and this particular data table can be applied for any type of a step it's not only for when you can apply for given also you can apply for then also you can do that and automatically it will generate the data in the form of a data table so make sure data table is the class which is coming from cucumber right now if you really want to create a test step for that you can do that so like let me create one test step over here so let me create a class that is my test runner i'll be creating so a simple right that is a user registration a test over here click on finish and then i'll do one thing i'll just copy paste this exact all the cucumber options from here to here okay so let's simple copy paste and if you really want to generate the report also you can do that and i don't want to use any hooks right now you can ignore this particular part step definition what is the feature file the feature file is that is a registration dot feature looks good to me and let's run it what happens so registration test.java run as junit so we are getting the result so let's run it again yeah this time you will see the better output here you can see user registration is done and this is a feature that is user registration with different data the step is absolutely working fine and you can see all the data over here in this particular format right so this scenario is absolutely working fine the first step the second step is user is on registration page and when user enters the following data this particular data and registration is successfully done and you can see the report over here if you really want to see that in the previous video i have already shown so let's see the report so i'll do one thing that i simple go to this particular report and i'll just copy paste this thing over here and here you can see the report over here that is registration.feature and the complete report you will see it over here like that so it's amazingly good you can practice and you can do this concept of a data table so that's all for this particular video guys thanks for watching this video and please like comment and subscribe to the channel if you have any questions feel free to ask in the comment section i'll be replying you over there thank you so much take care and see in the next video
Info
Channel: Naveen AutomationLabs
Views: 17,945
Rating: undefined out of 5
Keywords: CUCUMBER, cucumber bdd, cucumber datatable, cucumber with selenium, cucumber by naveen, cucumber latest videos, cucumber tutorials, naveen automationlabs
Id: ltuirHp0u14
Channel Id: undefined
Length: 11min 15sec (675 seconds)
Published: Tue Dec 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.