Transcript for:
Getting Started with BDD Cucumber in Catalon

[Music] foreign [Music] automation tutorial as you all know I have already published 22 YouTube videos covering different concepts of casual automation so this is our lesson 23 where I'm gonna start discussing about bdd cucumber framework by using catalog so from now onwards I'm gonna cover bdd cucumber framework automation by using catalon in multiple sessions so this is our part one of bdd cucumber framework right so I'm gonna cover the basic concepts of bdd cucumber framework by using Catalan how can we achieve end to end bdd cucumber framework by using catalog okay please do subscribe to the channel click on Bell icon you'll receive notifications whenever I publish more videos thank you okay so what is our agenda item so as part of part one session I'm gonna show you how can you create a project in Catalan Studio and then to achieve the bdd Cucumber framework how can we create feature files by using Teflon studio and then how can you create step definitions for the feature file that you have created and then how can we run feature files and also I'm gonna give a simple example how can we parameterize your feature file with the different test data sets okay and then I'm gonna show you how can we run the parameterized feature file by using Catalan Studio now let's jump onto the system and learn how can you create bdd cucumber framework by using Catalan Studio so this is my Catalan Studio okay so our first step is to create a project in Catalan Studio let's go back to Catalan studio and let us create one project okay let's click on new sorry file new and then project and name this as bdd cucumber framework okay and then select ok so type I'm gonna keep it as web itself and then click on OK so once you click on OK it's gonna create a new project in kettle on with all this structure okay so as you all know I've already published 21 videos explaining all the uh basic structure that is being created in the catalog you have test cases object repository test Suites right so now what is our next step we created a project now create feature file in include folder of Cutler so till now when uh like till 22 videos YouTube videos we worked on test cases right so we directly created test cases I mean we created folder and then we started creating test cases by automating the test cases correct so here because we are following bdd framework so you need to start working on include folder okay if you expand this include folder you will have a folder called features okay under these features I need to create a feature file so generally bdtt from work if you go to a sample bdd framework I think if you all remember I mean I don't know if you are aware of this if you say bdd feature file example okay if I search bdd feature for example right you will have one example uh probably let's go to images simple images okay given and when then so this is your feature file example okay let me expand this okay this is your scenario right and this is your Feature Feature and then your scenario and steps given and when then right so these are this is the way we write the feature file okay so this is all we we are going to write it as a gerking language means user understandable language okay so let's go back to feature file and right click here and let's create one either you can create a folder under folder you can create your feature file or you can directly create feature file okay so in this case I'm going to directly create a feature file okay let's name this as login feature file okay login dot feature click ok so what we are going to automate first as I explained you in my previous sessions we are going to automate same website that we used to follow example DOT test project IO and this is your login you need to provide your full name you need to provide your password and click on login okay that is your login function okay so if you see as soon as I create login feature what happened it created a file login feature file along with some predefined and with some predefined feature file with sample scenario right so let us just delete entire content which has been given by Catalan studio right it's an example I want to delete that and let me create from the scratch let us create from scratch okay first what is our feature my feature is login feature okay and then what is our scenario our scenario is test login with valid credentials okay test login with valid credentials and then given say given means it's a kind of precondition given user navigates to login page given user is user navigational login page if you see here there is some error what it says does not have matching blue code leave about that I'm gonna tell you later okay so basically this given is coming from where let's delete this let's enter given control space is going to show you so given is coming from your cucumber so it's your cucumber adding see if you see select this so basically it is coming from cucumber okay it's a cucumber dependency given user navigates to login page when again space say when is coming from cucumber when users user enters when user enters username and password okay when user enters username passwords and say here again and is also cucumber keyword and click on login button click on login button right what happens when user enters password and username and password and click on login button then then user user is navigated to where registration page if you see here I enter some name password see now user is actually navigated to registration page where he has to provide country address email phone number right so they'll say I'm gonna tell it as user is navigated to registration page right that's what I'm going to tell and let's save this so if you see this is your feature file to test so basically how many scenarios within this see for login feature you might have multiple scenarios again another scenario is like copy uh probably I want to cover a login with invalid and then I want to validate see here instead of clicking on login what happens user will be prompted with error message as invalid credentials right and here enter in valid username password like that how many scenarios you want to Define you can Define within the feature file okay let me delete this now let's work on this one scenario where that we clear created here now if you see the error it says step user navigates to login page does not have a matching blue code what do you mean by that so whenever you Define scenario in a feature file you should have a step definitions I have to Define so I have to create step definition for each step in the feature file nothing but step definition okay so for that you need to create step definitions how can we create step definitions so if you see e underscript left side pane you have to expand Scripts you can see there is a groovy so basically step definitions are defined in groovy language okay so here you have a default package right click here and click new and select step definition okay step definition here I'm going to specify it as login steps so these are my simple language gherkin language steps but this is where I'm gonna Define step definitions for each step in the feature file okay I'm going to mention this as login steps click ok so as soon as you click OK it's gonna create One login steps dot groovy okay login steps dot groovy so let me just simply collapse this import okay so if you see these are all my login steps correct so it gave me some sample code like what given depth so let me just delete all this now okay let me delete all this code and let us create from scratch okay let us create from sketch scratch okay so now our step definition okay first let's create let's let's what is my first step is user navigate to login page correct so let us create a definition for that so before that let me simply okay I think that's okay so now let's create a definition def Def navigate to login page first our first step is navigate to login page correct navigate to you can just the name of definition it's your wish okay navigate to login page open curly braces right and I'm writing the function definition function okay so here instead of writing actual code what I'm going to do I'm gonna use println for now so for now I'm gonna give you very basic concept in my part two session this is our part position right in part two session I'm going to show you one real-time examples okay so here I'm gonna write print Ln println what are we doing println I'm breaking the line so basically I'm I'm instructing to start from the new line to print okay that's why forward slash n okay I am user is user is the user is navigated to login page user is navigated to login page okay so that means when I execute this if it enters this particular definition It's Gonna print me user in navigator to login page okay done now but here one thing is see first step in definition also you need to use one keyword called at the rate because this is my given right at the rate given so here the red given if you say like this it's going to show you from where it is coming see this is from cucumber Java right so at the rate given rate given and this is my definition okay so here what is the step see I have to glue basically if you see here still if I refresh this so let's say recalculate steps still the error is showing me okay if I recalculate steps if you have a corresponding step definition then this error will gone but here I need to glue now how by using given function given given what is this this is my step cannot copy this as it is you need to copy this feature file step step from feature file given and name this function as this so now given sorry here double close okay given and this is my definition now save this so for this feature step now here save it right click and now do it as recalculate steps so it's going to recalculate see if you it's going to recalculate for some time C now there is no error for this line so error is gone that means this step has a corresponding step definition okay but rest all still does not have so let's now create all step definitions for rest of the steps in the feature file in the scenario okay so again now my next one is at the rate when Okay Internet when when is my step in the feed scenario this is my step in the scenario copy so before writing either it went anyway let's define definition death same thing okay def what is my enter credentials what is my function enter credentials basically I'm writing function for each step okay Enter credentials and what is this print Ln println again user entered username password user entered username and password okay done so now what is our next one next one is so here I have to again glue this step definition right where to glue I need to glue to my second second step in the scenario when so let's copy this when this one user enter paste it here done so then next what is next next again start definition user clicks on login button right click login function print Ln forward slash n user clicked on login button then okay and what is our next step user navigates to registration page correct user navigates to registration page oh before that I have to glue this particular step definition what is this and and this is my end statement right copy paste this done save it what is my last step So Def verify home page verify registration page so basically as soon as you hit login you'll be landing onto registration page right so that's why I'm gonna verify that okay this is my step definition open curly braces now println user is navigated to registration page see I'm not writing any code right now I'm just giving println codes okay I'm gonna write a proper code in the next part to session okay so it is our base okay done so now here again I need to glue this step definition by using then then I have to provide the same name the same step name user is navigated to registration page save this now save this entire step definition okay and let's go back to login feature and here still you can see the errors so you need to right click and recalculate steps see now all the errors got that means now this feature file scenario is valid because this particular feature file steps scenario steps has the corresponding step definitions okay hope you all understand right how can you glue your feature file steps with your step definition okay so this is done so now here right click here and then just do it as pretty format so what happens it's gonna do proper formatting here okay so that is done foreign I want to run this feature file as it is okay how so now let's go here you will be actually opening your feature file directly you can run here itself run as cucumber feature file or you can directly hit run button here as soon as I hit run here let's see run okay she started running and let's observe our um log viewer and the job progress okay so it is running so if you see here if you see the log viewer I can see see user navigates so that means it entered all the functions that we defined here right user is navigates to user enters username password click on login button so it entered each and every step definition okay if I go to console see I I should see println right println activities if you see here console see user is navigated to login page user entered username password user clicked on login page user is navigated to registration page and there are four steps correct so that means all our test cases pass pass pass all the steps are passed okay and now let me now let me tell you one more thing okay so now we start we completed creation of your step definitions right and now let's assume let's go back to login feature again okay now let's say I want to test this particular scenario with multiple multiple test data sets how can you do that okay for that in the feature file itself you can Define some examples means you can provide your data sets for username and password I want to use different username and different password for couple of uh scenarios couple of test cases okay I want to basically reduce parameterization so how can we do parameterization entering the username how can I do so for any parameterization you are gonna use these Square what I can say pointed braces okay in the same way here also password also I'm gonna use this okay done and now that means these two are my parameters now I want to parameterize these two who parameters with multiple data sets how can I do that so here examples you need to Define it as examples and here pipe symbol and my username sorry here examples okay and my username here right username password and now here here and one more thing is as soon as you convert this as examples you cannot name this as scenario you need to rename this as scenario outline remember that that's why it is showing error message let me do again so if you see here it shows error message what it says expected one of comment okay row scenario scenario outline so that's why you need to Define this as scenario outline because we are parameterizing it okay so done username password and let's say my first username is ravikant and then password is one two three four five and then next one is chandu let's assume next user is chandu and then password is same okay I'm using some dummy password that is given by that particular website now if you see I defined it but now again this glue code is not working now because we changed this as a parameterized parameterization so what you need to do you need to enhance this step definition let's go back to login here see if you want to right right click here you can directly go to stepper definition also okay find step definition it's going to highlight your step definition directly in the here it's gonna highlight that right click you don't have Find definition because this does not have any definition let's say for this right click click find the step definition see it directly lands here so now this user enter username password does not have a proper step definition because we changed it as parameterization right so now I need to change this function also how here instead of username we change it as a parameters right it's a variable kind of variable so now I want to instead of using a username I want to use a regular expression What DOT star that means anything see here it might user enter something and something it can be anything there you can Define as whatever you want dot star dot star so now it's good save this again now go back here and here right click and recalculate steps done so now your step definition is valid but again here in this function I want to use in the step definition function right here I want to pass username and password okay Enter credentials here in the in the in the inter potentials let's pass the string username and also sorry string username let me comma again string password right string password so basically what I am doing I am now entering the for this function I am actually passing username and password variables okay and here here also I'm gonna print Ln I'll say username is I'm going to Simply pass this variable here username is this and then password println password is again your password variable okay so here so basically what happens first it enters when I execute it enters this particular step and then it goes here and then this username and password whatever I am defining here right it's gonna so now let's save this session save this one okay so now I converted the function okay properly along with the variables username and password I think here I need to name this as password let me password this is correct now this is correct password okay save this so there is no perfect challenge right okay now let me run this now when I run this it should run two sets two times one is with ravikanth user name and the other one is with gender username correct let's save this now let me run this particular feature file okay this time right click and run as cucumber feature okay let me so it is now running it started running okay so running it should run twice one two see if you see here this is my first test case and this is my second test case let's expand this log viewer if you see here login enters chendu password login button sorry first one is this right first one is password oh okay password something is wrong actually password did not take the password okay see here this is wrong spelling is actually we named it as o r d password correct password so now let me run it again okay so now it should pick up all the values so this is perfect success so let's again Analyze This see login page first it entered ravikanth12345 as password login and navigate it and second test case here login page enter chendu one two three four five right that means this particular scenario has been run run twice two different sets of data right so now how can I mean this is not proper report but when I create test suite and then if I run this both I mean this scenario right you can see proper test results with a test report also okay out of these two test cases how many passed how many failed all these things okay but now what we did under step definition I just entered some print Talent statements but instead of this I'm gonna next session I'm gonna show you with example proper login page I'm gonna take and then I'm proper code I'm gonna write in the group view okay so now hope you all understand how can we create a basic framework of bdd cucumber in kettle on okay and then if you have any queries leave your queries in the comment box I'll try to respond to your queries so now in the part 2 session I'm gonna show you a real-time example with couple of scenarios by automating the scenarios in bdd cucumber okay hope you all understand the concepts of bdd cucumber framework by using catalon Studio as part of our part one session stay tuned for the next sessions where I'm gonna cover more advanced concepts of bdd cucumber framework by using Catalan please do subscribe to the channel click on Bell icon you'll receive notifications whenever I publish more videos thank you [Music]