Selenium Cucumber Java BDD Framework 5 - Parameterization & Data Driven Testing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this session I'm rocof and you can find all my work on my website automation step-by-step comm in this session we are going to learn what is parameterization and what is data driven testing and we will also see our demo and as always I am going to go very basic step by step and we will start from scratch so let's get started and the agenda for today will be we will learn what is parameterization what is data driven testing and then we will see a demo where I will run a future file multiple times with different sets of data the prerequisites are you should have the project set up with required maven dependencies of cucumber and selenium and this we have already done in the earlier session and we should also have a sample login test created and this is again we have done in the earlier session so we have already completed the prerequisites now let's get started and to start with let us learn what is parameterization let us take an example so if I want to login to an application the steps will be open browser navigate to login page enter some text in the username box here I'm entering logoff and then enter a password in the password box click on login button and then verify the user is on the home page now here if you see the data or the values we are using for username and password Raghav and one two three these are hard-coded values now in place of these hard-coded values if I use some variables like I use user for the username and then I use a variable pass for the password now here I have actually done parameterization so parameterization is the process where we add variables and then we refer the values from the variables in our tests now when we go to the next step that is we have done parameterization and we have variables now we can refer the values for these variables from any external source or a data file like a CSV file or excel file or within the script any script as well so here I can refer the value of username from this file and password as well from this file and I can now also have multiple sets of data or multiple values or sets of username and password and the test will run accordingly suppose I have three sets of data here that s will run three times for different values of username and password and this process we are we are referring the data from an external source and then the test is running as per our data provided this process is called as data-driven testing so we have learnt:about parameterization and data-driven testing let us now see a demo where we will run a feature file multiple times with different sets of data step number one is in the future file we have to select what are the values that needs to be parametrized so let me go to my Eclipse as of now I am on Windows you can also follow this on Mac operating system and here is the project that we created earlier cucumber Java in the if I expand this here I have my project where I have my feature files here so this was the feature we created earlier for login and here this is a very simple scenario where we are doing a login and we are entering user name and password and if I show you the step definition of this feature file so here this is the step definition and here if you see the step where we are entering username and password here we are having this hard-coded values so now I will go to my feature file and then these are the two values that I want to parameterize username and password so I have done step number one now we have to put these values into conical brackets or double quotes so that we can do parameterization so I will use this or put this values within this conical brackets like this so this is how I am doing parameterization here and then step number three is we have to change scenario to scenario outline so whenever we use this parameterization and we use data in examples section that I will show you in a moment we have to make this a scenario outline now you can also just use this have this parameterised here and in the script or in the step definition you can use multiple values but I am going to show you how you can use a data table within the feature file and for that we have to change this to scenario outline and then next step is add examples section where we will add our data table so I will say examples and a colon and then here I will add the values or the data for username and password so I will give a pipe symbol this is the syntax and I will say username this should be the same as this value and then I will give a pipe symbol again and the second variable or parameter which is password and then from the next line I will start giving the values for example I say here Raghav and 1 2 3 4 5 and I believe the password that we used for the application is 1 2 3 4 5 that's right so I'm going to use this and then I can also add more values here so let us say I say le and the password is again 1 2 3 4 5 and a pipe symbol now just to correct the formatting I can do a right-click and say pretty format and this is all done and here we have added the values for our data and then we have done step number 5 that we have added the data for the parameters in example section step numbers exist now we have to go and update our step definition accordingly because we have changed this step so if I just go to my step definition here you can see we have just given here user enters username and password and now this no longer matches this feature step here so if I go here here now have when user enters this thing either I have to use it directly like that or I can use regular expression so instead of username I can say in brackets I can say dot star that means they can be anything here and similarly here also I will say dot star so that means now it can accept any values here and the second thing I will have to do is because now I am doing parameterization I have to get the values of username and password from this data table here so for that in this function for this when statement in the brackets now this throws declaration I had added because I added this thread dot sleep let me just remove this so this is more simple and easy to read so in the function here I will pass the parameters so I will say string username comma string password so this is of data type string and I'm entering these two variables username and password as per whatever I have given here in my feature file and now instead of these hard-coded values I am going to refer these variables that is username and if you press ctrl spacebar it should show you or the suggestion of this username and then here this password should come here so this is password make sure it is not under inside course because this is now our variable so I am now referring username and password here and now I will save everything and go to my feature file and let me try to run it I will do a right click run as cucumber feature and let us see so let me just check very quickly looks like there was some issue so here it says the version of chrome driver only supports chrome version 81 and maybe some issue with the versions let me check very quickly if I go to my drivers folder where I have all my drivers added yes this is the chrome driver dot exe and if I go to my Chrome browser on my system and go to help about Google Chrome so here I have a version 83 so you can either try with the latest version of Chrome driver or according to the version of Chrome browser on your system so for that let me check I will go to the let me directly go to the chrome driver download and I will go to this chrome driver downloads website and here you can see we have as of now we have latest version 84 and my Chrome browser is on version 83 so you can similarly I can test with either chrome driver 83 or 84 or the whatever is the latest version and I can get the Windows as I am on Windows and then try this let me try this with a different browser that is the Firefox browser and for that I will go to the selenium dot dev website and here I will go to the downloads section here and scroll down here we have browsers I will go to the browser section and let me check for Firefox I will go to the documentation and you can see for Firefox we need the Kiko driver and here are all the versions so if your Firefox is 60 version 62 whatever maximum it is you can use the latest which is 0.2 6.0 and here they are the releases so let me also go to the gecko driver details page and here we have all the releases so let me first check what is the Firefox version on my system so I will go to my Firefox and go to help and then go to about Firefox so my version is 76 version so I should be able to use the latest Kiko driver so I am going here this is the latest one as of the time of recording this video and I will go and get the Windows File here so we have Windows 32 and Windows 64 so you can get according to your operating system now if I go to if I go to my computer or this PC do a right click and go to properties here you can see I am using a 64-bit operating system so I'm going to use that 64-bit I will download windows 64-bit and it is here and I can extract it and now I will copy this inside my project drivers folder so you can also refer it from anywhere on the system but as we have learnt in the earlier session it is better to keep it within your project and then refer it in a relative way so here I will now go to my step definition and I have to change it here as well so instead of Chrome we are now using Firefox and for that here I will change system got set property web driver instead of Chrome I will say dot decode driver and again I have to give the path of Kiko driver so here I will again change this to we could drive a dot exe and then here instead of new chrome driver I will say new Firefox driver and that's it I should be able to run this now on Firefox I will go back to my feature file do a right click run as cucumber feature and let us see yes it opened the firefox browser and yes it goes to the application somehow it did not enter the data it is running two times because we have two sets of data which is fine but it did not enter the data let me very quickly check the console and here here we have some issue so it says step user enters this statement is defined with two parameters okay and however the cat can step has zero arguments I think some issue with regular expression let me check very quickly I will also add a gap and dollar symbol here so here where I'm adding this I will also say here gap and at the end I will say dollar I will save this and try to run this again so let us see this time opens the browser okay so I think this was successful it was very fast so you could not see the actual login happening or let me again go and add some wait time here so here let me add a wait time I will say thread dot sleep this is not good to add hard wheels but just to show you that on this demo I am adding this so it will be it for two seconds before clicking on the login button and let me also add the through stickler ation here I will save this see if the project right click on feature file run as cucumber feature and you should be able to see login happening this time so it opens the browser goes to the application and you can see it enter drug her and the password and this is the first set of data and now it will run gained with the second set of data so it goes again and this time it enters LA and the password and locks in so this is working fine all right now in case you are using the data file like this and examples we have to use it in this format that is conical brackets the data should be in conical brackets otherwise if you're not using a data table we can also use it in double quotes and then in the step definition we can pass the values here so this is one of the other ways and this is how you can parameterize the data and do data-driven testing in your feature files so we have done step number six and we have also done step number seven that is we have executed and verified I hope this was useful for you I will meet you in the next episode thank you for watching
Info
Channel: Automation Step by Step
Views: 32,172
Rating: undefined out of 5
Keywords: selenium cucumber data driven testing, cucumber bdd data driven testing, how to do parameterization in selenium cucumber, selenium cucumber how to create data table, selenium cucumber bdd beginner tutorials
Id: wC2Xyuvkntc
Channel Id: undefined
Length: 16min 22sec (982 seconds)
Published: Tue Jun 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.