Data Tables in Cucumber - BDD Framework with Selenium - Part 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
otherwise this is Naveen here welcome back to selenium and taking about training so guys in cucumber so far we have seen that if you see the checklist and you compare that okay in the playlist we will see the last chapter I mean last topic we covered in to remember that how to do the data-driven testing right like with the help of scenario outline and examples keyword in part number three okay data-driven testing now that's very important topic but there is another way also to do the data-driven testing by using data tables okay how to do that and what is the difference between test data table and okay what is the different between let me in just a minute yeah so what is the difference between data table as well as examples keyword and scenario outline okay sometimes we use scenario outline and sometimes we have to use examples keyword okay apart from that sometimes we have to use data different color okay concept also so how to do that so to do this thing we have to use we don't need to use any keyword but okay we don't need to use any regular expression also but the concept here is very simple it's very very simple let me start so what I'll do in free CRM dot-com application we will log in and after login what exactly we will do we will let's see we will go to deals and you will click on new deal okay new deal link and we will fill this particular deal some information and then we will click on save button okay okay so we will pass this particular data with the help of test data table in kimber how to do that okay so what I'll do I will create a new feature file simple so for feature file we have to make some changes let's say I'm going to create my feature file name is deals dot feature okay so all the scenarios related to deals we will be writing over here so simple I will be writing that what is the feature my feature name is okay deal data creation okay this is my feature okay deal data creation this is my feature that wounded it save okay okay deal data creation don't give any space after this case okay and then my scenario here we don't need to use in area outline scenario outline will be used only and only when we have to use examples fewer days okay so here we don't need any scenario outline okay so simple we have to use simple scenario keyword the scenario keyword will be like this so I'll take this in a vo keyword from here okay I'll take it something from here so that we will okay so instead of scenario outline and be using scenario okay and free CRM create a new deal scenario this is my scenario name same thing given user is already on login page when title of the login page is free CRM ok the user enters username and password okay lettuce okay let's see user enter username and password we will okay pass in the form of data table okay how will you do that so no need to write this this thing simple we will write we will be writing like this okay user enters let's see simply username and password now how to pass the data for username and password without examples keyword so immediately after this particular step okay okay test data table is always created immediately after this step so if I want to use some data for this particular step immediately after this line I have to use that particular data so how to use the data in the form of pipe same thing let's see my username is Naveen gay and the password is test at the rate one two three and this is the pipe so I know that okay this is my username and this is my password if you have some let see five to ten data so pipe separated you have to write like this and the next step is then user clicks on login button user is on her home page then user moves to the new deal page and then user enters deal details what kind of date it is okay we will fill over here need details okay what are different DS details we have to write the first detail let's see Titan and amount okay titled amount and let's see we will enter yeah let's see title an amount we will write over here okay and let's see probability and commission also we will write so simple the titer no need to write any column values and nothing simple pipe separated value so my title is let's see the deal title is let's see test deal okay pipe give some space like this okay test deal is the title company I don't want to add I want to add amount let's see amount is thousand space and then Commission and probability so probability I'll write let's see probability is let's see 50% like this okay and Commission is let's see 10% like this okay so this particular data one two three four values we are entering for this particular step so okay so this is called as data here I'm passing the test data this is called test data table okay so this test data table immediately we will be writing immediately after that particular step okay after that particular step we will be writing over here okay it means this particular test data is only applicable for this this particular test data is only applicable for line number 12 for step number 12 but an examples keyword it's totally different in examples means this particular examples keyword is applicable for the entire test case and this is my entire test case this is my entire test case this examples keyword I can be used in line number seven also for line number 11 also for line number 15 12 13 whatever this examples keyword is applicable for the entire test case okay but tested here okay this this kind of format if you are using okay I mean this is only applicable for this guy okay this is only applicable for this particular line okay so this is and we don't need any keyword and don't need any outline and examples keyword so they will ask you what is the difference between scenario and scenario outline okay and what is a different how will you achieve the data driven testing without using this in our UN without using sonar your outline examples keyword okay so this is how we all achieve now I will create in my I will go to a login a step definition let's see this is a mess step definition class and then inside the another class what I will do I will give the feature path of this particular deal start feature okay so I'll write these dot feature okay and dry run is equal to true and then we will see what are different steps are missing so we will implement those steps in a step definition class okay so let's run it so we will see that couple of steps definitions are missing so this is that then user moves to deal new deal page this particular task is missing okay and so let's do that so or I'll do one thing let me create a new step definition okay so that it will be clear so let's see the step definition okay let's create a new class for you guys so that you will understand properly and my first step is given user is already on login page right so I will take it from here that given user already on login page so I will take it from here so this web driver also I will take it and over here I'll write okay so my first step is done after that what is my second step title of the login page is free CRM so tied to all the login pages fees here I will take this also without any problem fine I'll take it this now now the third one is then user enters username and password okay so I'll take eight this but I'll modify this because I don't any regular expression and these kind of things so simple I will do one thing that and then I'll copy this exact the username and terse username and password okay very carefully okay and after that what do we have to do username and password okay now for this particular step we are using this particular test data right so we don't need to create any two variables like a string username common string password okay just we don't need that what we need in this particular method what we need days now see it very very carefully we need data table okay one data table like that you have to write ok data table okay and then let's see you can create any any variable of data table I'll tell you what is dinner table here that is credentials ok credential is the variable and this data table okay you have to import it from cucumber dot ap okay so this data table god this is a class is available in Kakuma AP okay and with this particular variable okay this is the object variable you have to use credentials dot so what exactly this credential is doing credential is referring this now credential is referring this particular object okay I mean this particular test data so this is zero test data and this is what this is one so this is zero index and this is one index so what we have to do right okay dot what we have to do dot get zero okay dot credentials dot just a minute okay no no no not like this I've also forgot just a minute what we have to do yeah before that we have to write we have to initialize this particular credentials so how to initialize credentials dot okay credentials dot one method is there row method okay drew I think they have changed - sorry wrong method not row yeah maybe I forgot in this line yeah raw method is their draw method what exactly it will give you raw material will give you the list of list of strings okay so how exactly you can store this particular raw in list of list of a string now see it carefully list off okay list of list of the string you have to use face okay and let's see this is my I simple right data is equal to like this okay list of list of object Rock a list of list of a string you have to use and this list is available in Java dot util okay input so we have to initialize these credentials dot raw we have to use dot raw method will give you the complete data table axis over here on this particular okay data now this is 0 location and this is one location now what we have to do weighs very carefully you have to use this particular data okay you have to use data dot get method is there get 0 how many okay which index get 0 okay why I am using get 0 because we have only one row get 0 this is of 0th row and from 0th row i want to pick Naveen K and the B is also available on 0 so 0 throw and 0th element like this get 0 okay dot get 0 like this this is data dot get 0.80 is pointing to Naveen why this is zeroth row and zeroth element okay if I create one more row so data dot get to one I have to write okay like this and the same thing for password what I have to do data dot get 0 okay and then password is available on second look I mean first ok 0 location and this is first index so I'll be using 0 ok dot get one I have to use okay this is what we have to rent like this for username and password okay got it okay so this is what we have to write now after that user clicks on login button okay so I will take it from here the user clicks on login button it's already available this method we have already written so yeah so the user clicks on login button which is also fine and after that user is on home page fine so user is on home page method I'll take it from here that user is on home page okay find user is on home page this is also fine and then its next step is user moves to a new deal page ok guys so what we have to do earlier we have written user moves to new contact page so we will modify this accordingly that user moves to new deal page this is the exact line it should be over here that user moves to New Deal page user move to New Deal page and then to click on this particular deal ok we have to click on new deal so we have to mouse over on deal and then we have to click on noodle just like we did mouse over on contacts and click on new content okay so I'll just change it to deeds okay this is deals and then new deal ok first mouse over and then click on new deal so what exactly it will do mouse over and click on new deal so this is also fine after that what is the step then user enters ok deal details so I will take it from here that user enters I'll modify this method ok guys user enters deal details and I don't need such things okay all these regular expression I don't need that I don't need same thing this thing also I don't need this what exactly I'll do again data table and let's see deal deal data okay I'll create one data table variable deal data and then same thing deal data dot raw and this deal data dot row will give you the list of lists or for Strings list of string and let's see the data is deal values is equal to this okay now by using this deal values what is your okay we will write the code okay now we will write the code for entering the values so how many values we have to enter okay one two three four so we have to enter the title so for let's see what is the title so we will inspect this we will use we can use title ok ID is equal to title simple okay so very simple that driver dot find element by dot ID and ID is title okay dot sendkeys no in send keys what we have to do D values dot get zero because only one bro okay this is zeroth row and pick the first value this zero to value so this is 0 this is 1 this is 2 and this is 3 okay so dot get 0 and dot get ok get 0 0 throw and 0 to L you ok similarly we have to write it for next value so the next value is we have to enter amount right so amount okay that spiders a my own name there is no ID ok IDs there yes IDs it amount is the ID so I'll enter amount okay and then get 0 and first value we have to enter ok ok and for this guy probability what is the probability ID this is the probability ID ok probability and for Commission this is ID is Commission I have put commission over here so this is 0 this is 1 this is 2 and this is 3 right so get 0 get 3 simple get 3 is this 0 1 2 3 so commission will be 1050 is a probability thousand is the what thousand is not amount and title is this okay cool we don't need to write any column name nothing simple data pipe separated and then close the browser so closing the browser we have this method okay let's see close the browser right so all the steps we have defined over here I will close this deal start feature and open it again let's see now everything okay still is saying that multiple definition found per user is already on login page okay why multiple definition because the same thing is also available in deals or curative definition also okay so what I will do I'll just select this all these things and then I'll comment it okay so that not sorry deal ordeal definition sorry what I will do a login step definition and select and comment all these things so that there is no confusion between two definitions okay and I'll close it and it see and open this deal short feature again now it's perfectly fine without any yellow line okay there is no warning okay so this is a DS dot feature and this is my deals step definition rod Java login step definition dot Java I have commented okay simple I have commented now what I will do I will go to my other class and this is my step definition I have this deal definition it will execute this it will be ignored why because everything is commented over here okay and this is what deals dot feature and will dry on equal to two I'll run I'll check if any step definition is missing or not simple run it so everything is fine no step definition is missing everything is mapped properly okay all the steps are mapped properly like this so thing is fine that we have already seen what is the purpose of Dragon in the previous sessions now let's make a dry run is equal to false okay and let's run if it is working or not let's see so run as J unit so let's see it is launching the browser okay fine let's see it will login it is picking the value see it's picking the value from table the test data table that we have created in feature file then it should go to DLC yes it's clicking on new deal and drink the value see all the test cases are absolutely all the test steps are absolutely fine if you see ok scenario and all the steps are perfectly working fine okay but the problem here is couple of things that the user enters deals details but it's not showing any okay deals detail which or it is we are providing over here it doesn't show all these things over here okay in the console also it does not show that what kind of data we are entering but sometime it's really helpful for a specific ok a specific data this particular data is only applicable for this thing so I don't want to pop I don't want to be you know I don't want that okay this particular data should be part of my examples he would okay so in that case we don't need that examples keyword okay although generally we don't prefer this particular method okay test data method okay we always use scenario outline for parameterization of test cases okay so this is always a member race this is a very important interview question and sometimes in some projects also they have implemented like that okay that without using scenario some scenario doesn't have any scenario outline an example keyword so you you can create scenarios like that also okay all that a very good approach somewhere but against term as compared to examples keyword in scenario outline somewhere I would prefer okay this particular thing this is really good scenario outline and this particular data is applicable for the entire test case you can use this particular data anywhere okay but this particular data is only and only applicable okay if I written below this particular line its mean it's applicable for the bow line okay it's applicable for the above line in this particular it is applicable for this particular line just above that data it's okay it will be applicable okay that's the only difference and you just need to remember this thing guys okay the table concept data table is the class okay you can see that I just imported in the import section cucumber a paid or data table it's a Class C means class okay just reference we have to create this method you have to remember wrong okay they will ask you at a time of NW what is a method available in this particular day today we'll draw method and then it will return one list of list of string because all these values are strings value okay so that's my list of list of string it will return and then get 0 get 1 get to get 3 simply 0 throw get 0 is representing the row and and 0 1 2 3 these are representing columns okay and lets you tomorrow if you have multiple data you can create multiple deals also like that the same set of data you can create like this okay test deal to with 2000 the chief will then 80 and then 20 like that also you can create and in that case the problem here is guys if you create multiple set of data like this the problem area that's why i don't prefer this approach how will you how will you do that you have to execute the same test case again and again but how we'll do that right now you are entering the value is available on the first row that 0 is row but the same code you have to write it again okay same code here to write it again to create a deal once again you have to move to the deal page again and then write the code again and again okay write this particular code again and again if you have 50 rows then again you have to write the data or maybe you can create a self same function sum function pass the data like it's up to you how exactly you want to okay but extra effort you have to put it over here but in examples keyword this is very very good example here with that automatically that if you have three rows the entire test case will be executed three times for this set of data for this set of data and for this set of data for three times if we have 50 rows automatically it will be executed 50 times right that's the biggest advantage with examples keyword but this thing is missing in this approach this particular thing only one set of data let's see if you want to use okay for the specific step if you want to use then in that case we can use this okay although that's not a great approach that's why it's not a greater it's a good approach but not a great approach okay so this is one of the option they have given in the form of test data table okay and quickly if you see the report also let's refresh your page I mean the project go to the test output index dot HTML file you will pick and copy this open your browser in the new tab simple execute and then you will see that this is a scenario and see it's showing the data over here like this use the enter username password this particular username password we entered user enter D details like this without any column names so that's why I like the reporting in the reporting also chewing the data but what kind of data it is what are different attribute that we have entered what is the column names it's not showing okay that's a problem with this particular approach but it's good to have this particular knowledge because they will ask you a type of NW and some other scenario we have to implement like this okay that's where it's important okay you should not ignore this okay so that's all for this particular video guys in the next video that we will see how to do the tagging and everything and I think one more beauty we will create for extend I mean for report generation with respect to extend report and everything and I think then with respect to consumer everything is done okay and then we will see one more video that Kakuma integration with Jenkins okay so that's all for today and let me check in the code also so this is the repository I'll check in the core into my repository for the entire code base base this is a cucumber selenium framework right I have already imported around 4 days ago ok for the third video I created this is a fourth video I'm going to create I have already created so I'm going to check in the code ok so I'll go to my terminal right and then simple I'll go to that location and I will check the status that get status so these files I have I've modified and this step definition file and all those things I've added now I'm going to check in the code simple good ok add dot check the status everything is green ready to commit so get the commit minus M added code for tester data table concept ok and simple I'll use get push origin into master branch and it will ask my laptop password enter it and done hundred percent is done and it's in to master to master branch code is pushed and refresh this page you will see that 23 seconds ago added code for test data concept and if you go to the main Java and in the feature file and check the deal start feature see data is available now right and in the code in the step definition also you can check deal step definition we have added the code for C data get 0 1 ok like this 0 1 2 3 like this ok the code is already available here please refer this code and let me know if you have any issues ok if you have any queries please write down in the in the comment section and you can ping me in the group also in the telegram group and feel free to ask me an equation page okay so Pease this is my channel and please subscribe to the channel guys the lot of a lot of new things are coming in future and okay some amazing learning you will be having okay with respect to automation and new tools and technologies so please click on the subscribe button share with others with your friends with your colleagues and feel free to ask any questions if you have okay thank you so much I'll see you in the next video
Info
Channel: Naveen AutomationLabs
Views: 88,426
Rating: undefined out of 5
Keywords: Selenium, Cucumber, Cucumber BDD Framework, Selenium with Cucumber, BDD Framework using Cucumber, Examples in Cucumber, Scenario Outline, Perform Data Driven Testing in Cucumber, Difference between Scenario Outline - Example & Data Table
Id: W1NhwqWC29M
Channel Id: undefined
Length: 29min 11sec (1751 seconds)
Published: Thu Nov 23 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.