#4 - Cucumber Feature File mapping with Step Definition - Important Tips

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this conference will now be recorded hey guys this is naveen welcome back to naveen automation labs so in today's video guys it's very quick video that a couple of things first of all that we have to refactor our project structure that we have created second thing is that uh how will you write a step definition when you write against any feature file and then what are the different mapping concepts are available between feature file and the step definition file a quick video i really wanted to show you that the moment you change your feature file step immediately it will be reflected it will be flagged that okay there is no step definition is available for that particular step so let's see how to do that so first of all that instead of this src test java all my feature files should be returned under src test resources although it's not compulsory it's not mandatory that we have to write under src test resources but according to the maven structure that according to the build automation structure that it should be part of your src test resources because these are my resource files so what i'm going to do that i'm going to create another source folder over here that is src test resources and click on finish and i'll do one thing this particular package i'll right click on it and completely move it over there from here to here src does resources and i delete it from here just simple delete that then you can see that under sr it has resources i have this particular search dot feature that we created last time and then my step definitions are available under search steps dot java it should be part of your src test java and then under src main java my actual implementation i'll be writing over here now second thing is that what you have to do uh you have to download the plugin and that we have already downloaded that is cucumber eclipse plugin but you have to keep checking that there is a upgraded version or not so you can check the upgraded version over here so simple go to this particular site and the previous video also i have already told you that you have to go to install new software and just copy paste this particular site and then here it will show that eclipse plugin over there okay it's saying that no software found that's okay let me edit it once again you have to copy this particular url so just copy this once again over here and here you can see that okay cucumber eclipse plugin you select it and click on next this plugin is already available on my eclipse so i don't need to do that once again that's where it's not showing any next button but in your case please update the eclipse plugin from this particular url i'll share this particular url in the description of the video and then click on next you have to accept the license agreement and then just simply restart your eclipse once and that's it after that what you have to do guys that let me just close this feature and i'm going to create one more feature file so let's take one simple example i'm going to create one a file over here and my file name let's see i'm giving um let's see uber dot or feature in this particular uber dot feature i'm going to write some uh some feature and one or two scenarios that say i'm going to write so let me just delete all these things i don't need that and then i'm going to write that my first feature that is let's see for this particular feature you can simply write the moment you write c feature is a keyword suppress control space automatically it will give you an option that okay yeah you have a feature and then what is the feature name so let's see this is my uber booking feature then what is the scenario so you can write your scenario whatever the scenario let's see i simply write booking cab over here and then you will start writing given press control space given will be coming automatically and your simple right let's say user wants to select a car a type whatever the car type let's see car type i'm selecting sedan from where from uber app and then i simply write when user selects car so user wants to select the car type sedan from uber app and user selects car set up let's say i'm writing simple and pick up point as let's see i'm writing my pickup point as uh bangalore and a drop location let's see i'm simply writing some another city over here let's see put it like that and then i'm simply saying that the driver starts the journey then once the journey is over the driver ends the journey and then i'm simply writing [Music] instead of then i'm writing and over here and and i simply say that then once again then a user pays something let's see 1000 usd like that okay so i'm writing it like this uses selex car ends the journey and start the journey and the journey and pay a thousand dollars and you simple save it over here moment you save it just close it and you open it again fine now what i'm going to do i'm going to execute this particular uber dot feature so that i can get my step definition suggestions in the console because we don't have any step definition written so far so i'm going to run as run configuration and let's select this particular project once again that is my cucumber practices and select this particular uh project from the workspace so we will go to this uh cucumber practices go to src go to our test resources app feature and uber dot feature we have to select this particular file apply and click on run when you run it on the console you will see that okay yeah we don't have any step definition defined for that particular scenario so i'm just going to define the step definition over here so simple copy this entire thing and then what i'm going to do one thing you notice that here can you see this one exclamation mark over here that against this particular feature file we don't have any step definition and right now it's not giving you any flag over here that okay yeah for this particular step do we have any step definition no so for that what you just need to do right click on your project and go to configure and convert to a cucumber project can you see this convert to cucumber project here you can see that okay it's converting the cucumber project and you can see that okay all these four or five steps are flagged now can you see this particular orange color it means with this particular warning it's saying that this particular step does not have any matching glue code look what means there is no step definition is defined for that particular step so immediately the moment you write a step over here immediately it will give it to you same thing if you check it for the search feature it's not showing anything for search feature any any glue code warning it's not showing that you can see a green color code over here that okay yeah it's glued can you see that glued with with this particular step over here in my search steps so against that particular step i have already written uh at the red given method a particular glue step definition i have written so for search feature it's not giving you any warning but for uber dot feature it's giving you all these warnings why because we don't have any strip definition for that so what i'm going to do i'm going to define those step definitions so right click on it go to new and create a class and let's see this time i'm going to write uber a booking steps i'm going to write and simple copy paste those methods and you're simple import all these given when then the movement to import go to uber dot feature and you see that okay all the warnings are gone it means it's coming as a green color it means all the steps are absolutely mapped with the respective step over here fine now you can do directly jump over here from here directly that okay yeah against this particular step where exactly the step definition is written very simple press ctrl and from the macbook you can press command and click on it you will reach over here so this thing is coming because of that plugin that we have downloaded that's why this plugin will help you a lot to move from your feature file to the step definition file it will give you the respective warning also that this particular step is a defined or not in your step definition and then after that you are just good to go and let me just simple remove this particular throw exception code i simple write a simple system dot out print talent over here that yeah whatever i'm writing let's see i'm simply printing the same statement over here one thing you notice that these are coming a regular expression like that these are called cucumber regular expression that is the next chapter i'll tell you what is the difference between a cucumber expression and the typical java regular expression i'll talk about it later so that's why it's coming in the string because this uber dot feature and sedan i have written within double quotes so cucumber will automatically recognize that okay you are passing one string feature or one string parameter over here and the same parameter you can pass it over here so instead of the string i can give a proper name let's say this time giving card type over here and then same thing select the string pick a point and the drop location also in a string and then you can change the parameter accordingly that again this is my car uh type what is your pickup point so i create one string over here that this is my pickup point and this is my a drop point or drop point location or whatever pick up location and drop location i'll write it better like this location and then accordingly you can use these variables in your implementation over here simple so i'll be writing let's say this is my step one i quickly write and this is my step number two i'm not writing any implementation guys this is just for the demo point of view later on when we integrate with selenium or something else then i'll show you how to write proper selenium code and everything and then let's see i'm writing here firstly step number four this is my step four and quickly i'll be writing for this guy also step number five simple and here i'm see here you can see that user pays what i have written over here i have returned 1000 000 will be considered as a numeric integer value so that's why it's showing you end as a regular expression over here and the same you can write that okay yeah what is the price that you are paying for that right and just for your reference i'll do one thing along with this particular step one i'll do one thing that i'll just print this card type so that you will get to know that whatever the car type we are passing in our case we are passing sedan so sedan will be given to this guy and the same card time will be printed over here on the console same thing let's see i'm writing that is step two with my uh different card type over here card type plus sorry about that card type then i'm writing plus whatever the pickup location plus with one space and then i'm writing whatever the drop location that you're writing drop location and c small okay here we don't have any parameter we don't have any parameter here i'm passing parameter as price so the same price i'm printing it over here with the step number five okay now one thing you notice the moment i add let's see from uber app and i'm writing application and you save it immediately it got flagged why because automatically it will recognize that you have added instead of app you have written application and the same corresponding step definition is not written over here so you can see that okay user wants to select a car type from user app so i have written app over here but here it's we have written application it means we have updated our step definition so we have to change over here as well so let's say i'm writing uber application the moment i write and save it immediately this flag is gone sometime what happens it takes some time or maybe automatically it does not get saved so what you do simple close it and open it again and you will see that yeah everything is in green color everything is mapped over here like that same thing vice versa if i do that okay uber application if i'm writing edgy system over here and then you simply save it then you come over here immediately it got flagged once again because we have updated in the step definition in my java code but here we haven't updated over here so that's why it works vice versa like that so let it be like this and then let's run it again and let's see what happens so a simple uber dot feature i'm going to run as run configuration and you can see uber dot feature with the same project you can select and then click on run and this time you go to the console and you can see that okay all the five steps in this particular scenario absolutely working fine and you can see on the console that step one sit down given user selects card types it done that is what we are printing in our console that is step once it done the same thing you can see it over here that is step one sedan then the next thing is that a step two card type you can see that okay yeah step two is my card types are sedan bangalore to pune that is my drop location and pick up location and step three four it's normal driver start the journey and end the journey along with step three and step four and step five is the price with thousand dollars right so like this guys it will work and then here you can write your whatever the testing logic or business logic with assertions and everything you can write it over here perfect so this is how we work with the feature file mapping with the step definition and please download this plugin uh from this particular location that i have already shown you very very helpful plugin and then if it is are not showing please convert your curcuma project to the i mean this particular project to the kimber project i'll repeat once again right click on it and go to configure and convert to kikima project and that's it it will automatically convert it and it will show this maven with green color over here can you see that maven with green color so this is not a maven java project now now this will become a maven cucumber project okay guys so that's all for this particular video i really wanted to cover this quick tip so that we can proceed accordingly in further upcoming videos thank you so much guys please subscribe to the channel let me know if you have any issues put it in the comment section if you're facing an issue with the configuration or any a plug-in configuration or a step definition configuration i'll be replying over there thank you so much guys thanks for watching naveen automation labs
Info
Channel: Naveen AutomationLabs
Views: 43,117
Rating: undefined out of 5
Keywords: cucumber bdd, cucumber feature file, cucumber eclipse plugin, cucumber feature file mapping with step definition, cucumber java project, first cucumber project, cucumber add framework
Id: IIhqhJfVUQ0
Channel Id: undefined
Length: 16min 21sec (981 seconds)
Published: Sun Nov 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.