#3 - Cucumber (BDD) with Java - Write your first #Cucumber Test with (#Gherkin) Feature File (2021)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is naveen here welcome back naveen automation labs so today onwards we are going to start with the cucumber framework design and uh today we will see first what exactly different components that we have to design and what are the different feature files we can create what are different options and then we will be using eclipse to create the feature file in the step definition and then we will write one one simple basic test today without selenium but we will see that how to create a basic feature file in the step definition and the runner so before that we will have to design some components over here so let's see these are the multiple components that i have created so first thing guys that we have the user story as i told you according to the bdd that we have a user story in the form of requirement documentation or maybe the business requirement documentation or srs a documentation is available and then then three amigos like we call three amigos over here po dev and qa they will discuss on this particular user story they will collaborate together and then they will create multiple of features over here they will create multiple scenarios over here so this is this component i'll be calling this is my feature file all right we can have multiple feature files so i can write that okay yeah these are my features feature files over here i'll be creating and the feature file i'll be creating with the help of gherkin keyword that i'll be using for that so gergen keyword in the form of given when then and getting is a gerkin dsl language we call it a domain specific language we will be using it how to create a feature file that i'll show you but in feature file we will be having multiple features we can have it so let's see this is my feature number one this is my feature number two and this is my feature number three and in fact in the same feature we can have multiple uh scenarios over there or scenarios outline will be there with examples and everything we will see that so let's see this is my first scenario this is my second scenario this is my third scenario that i have written and for each and every scenario we will be writing different uh scenario steps over there so let's see this is my feature number one uh i would say this is my feature file number one over here so i will say that okay yeah this is my feature file number one dot feature is something like this in this particular feature i'll be defining my scenarios over here so this is this will become scenario and under that particular scenario i'll be having multiple steps over here guys so steps that i have to write with the help of gerkin keywords like we have to use the concept of given then i'll be using given then when then and then like that so these are the keywords we have to use with the help of getting keywords and you can create multiple scenarios within the same feature and likewise you can create multiple features over here let's see this is my login feature this is my search feature under that particular search feature we can have multiple scenarios over there and each and every scenario will be having multiple steps so just for your reference let's see this feature is related to my login second feature is related to let's see forward search dot i would say a feature and then having multiple search based scenarios we will be writing over the third feature let's see i'm writing for something else uh let's see add to cart i'm writing a feature file and this particular feature file we will be having multiple uh scenarios over there now this is not a java code right this is not a programming code this is just a simple gerkin keywords and the common english formatted keywords i have written and scenarios i have written so these three guys sit together they will work up on the user story and then they will create multiple a feature files and then they will share with the developers and developers will perform the tdd approach over there a qa team they will start writing their automation test cases accordingly so let's see after this we have to convert this particular feature file we have to write the second thing is that step definition so this step definition will be in okay in any programming language for example we will be writing okay java it could be any programming language it could be python it could be a ruby it could be javascript anything there are multiple uh frameworks are available so in this particular video we video series we will be using cucumber with java if you want to use cucumber with ruby cucumber with javascript or any cucumber based family also if you really want to use with some other programming language feature file will remain same now it's up to you which in which language you want to write your step definition so in a step definition for each and every corresponding a feature that you have written we will be mapping okay we will be mapping with these a given method over here and then when we will write a separate step method over here for end and for then like that so here we will be creating a class that is called my step definition class dot java and then we will be writing certain methods over here so cucumber jvm library will give you certain annotations and the methods and we will be using those annotations let's see for given we will be using one at the rate uh given over there like that at the rate given at the rate then at the read when like that we will be using that and for every annotation we will be creating a method and this method will behave like a step over here now here we will be defining that okay which method is responsible for to or responsible to define that particular step and these steps later on can call multiple utilities let's see i want to use that page object model in selenium or i want to use let's see some a database connection or excel file connection or i want to do some api automation also in that case corresponding utilities in a separate java classes you can write it and these are methods the step method that you have written they will be calling these certain utilities for example i'm writing uh let's see some uh let's see i want to wait for a specific element or i want to let's see uh send keys or dot click certain methods or certain wrappers i have created in the form of utilities or the libraries i could do that other example let's see when doing interact with the excel file writing certain utility methods over here and then i'll be calling from these step methods over here so the mapping is very important this given a step will be mapped with this address given annotation likewise we can create a multiple one-to-one mapping over here and then we will create our step definition and it's up to you which language that you are using it once this is done likewise we can create multiple step definitions over here let's say this is my step definition for a login feature step definition for search feature step definition for add to cart feature dot java like that we can do that and then each and every mapping will be done from the feature file the respective feature file so let's see the search dot feature is mapped with this guy add to cart feature is mapped with this particular java class once this is done we can execute our code directly from the feature file like individual feature files we can execute it or we can create one runner file over here so what we have to do that the third component that we have to create that is called my testrunner.java okay and this testrunner.java will be using some cucumber options and the junit and we will be defining some basic annotations over here with different options like uh where exactly a feature file path over here with exactly a step definition file path over here in which format you want to execute you can define some tags over there you can define some a lot of other options we will see inside the test runner dot in java so i'm writing some basic run options over here so here we will be using a cucumber options and then we will be using junit runner and then multiple options we will be writing that okay where exactly your a feature file path with exactly your step definition path and in which format what kind of report you want to generate or all those things we will be writing over here so this test runner dot java will interact with your feature file over here like that so it will go to the feature file just because of feature file path we have defined over here and each and every feature file uh cucumber already integrated will get to know that okay yeah we have corresponding step definition file is available and we'll start writing and sorry executing these number of java classes and the methods and the steps and these steps will be calling a certain utilities that we have available over here and then it will generate a report output away okay so this will be the flow and these are the four five major components that you have to create whenever you have to work with any uh cucumber based framework or any bdd-based tools and automation over there so let's see how to do that so for that purpose i'll be using eclipse over here and then i'm going to create my first eclipse a maven project over here so you just simply go to new and go to project and click on maven project over here and click on next and then simple click on next once again and here you have to search for a maven plugin so i'll tell you which plugin that you have to search i simply write maven you have to search for quick start so please search for this particular plugin maven arc type quick start version it could be 1.4 1.0 1.1 that doesn't matter so we will be using a simple quick start plugin click on next and then here we have to give a proper group id so let's see i'm writing this is cucumber i would say youtube and then artifact id i simply write that okay yeah cucumber practices like that and then you simple click on finish when you see that okay guys cucumber practices got created under src main java src tells java and then we have this particular pom.xml file now before that guys you have to download one more plugin in your eclipse that is called cucumber eclipse plugin that you have to download so a very very simple and very useful plugin that will help you to create multiple feature files it will highlight all the uh you know features annotations and everything in the respective color so the readability will be improved and a lot of other features are available in that particular through that particular plugin you can add that so what i'm going to do that i'm going to go to google and then simple search for cucumber and what you need to do you just need to go to the first link over here so either you can download this particular plugin and here you can see certain features are available that new feature in this particular version it supports lambda expression for according to cucumber java 8 and a new step definition file wizard and syntax highlighting pretty formatting a feature runner with formatters so a lot of features are available over here and it's such a nice uh plugin you can take it you can directly drag and drop in your eclipse but i don't want to do that what i'm gonna do that i'll go back see this is the eclipse plugin you just need to copy this url and go to your help and then install new software in your eclipse and copy paste that particular url and here you will see that cucumber eclipse plugin you select that and click on next next you have to accept the license agreement and then click on finish it will ask you to restart your eclipse and then that's it i've already downloaded it that's why it's not enabling the next option for me so that let it be like that i'm not going to download once again you can do it by your own i can share this particular link url in the description of the video you can take it from there and please download this particular plugin i'm going to cancel it right now now here these are the dummy packages got created i'm going to delete them i don't need them under src test java also i'm going to delete them now what i'm going to do i'll open my pom.xml file and we have to add a certain properties and the certain dependencies over here all right so what i'm going to do that again you go to google google and then i simply search for cucumber java skeleton and go to this particular project this is the skeleton framework and for the examples point of view uh cucumber guys they have created we will go to its pom.xml file and from here we will copy multiple dependencies so the latest version of cucumber guys we will be using 6.9.0 that is the latest version recently released i'll just going to copy all these properties from here and then paste it over here in your properties section we will be using uh jdk version java jvm version 1.8 cucumber version 6.9 maven compiler plugin and all those things we are using it compiler plugin and the surefire plugin we are using like that then you have to add certain dependencies so there are three dependencies are available copy these three dependencies and uh simple i'm just going to remove this pareto dependency first and then add my own over here you can see that this cucumber version cucumber version is coming from here from the properties variable over here this is my property my version variable after that i'm going to copy those up plugins also which are available under build section so copy this entire build section from here and remove this existing build section in your pom.xml file and then copy paste those things and then we are using java version as a property dollar variable as a 1.8 over here and then you simply save it that's it after that you will see that in your project maven dependencies got added over here you can see that cucumber jvm and all those things got added over here once all these things are done what you do you simple right click on your project go to maven and simple update the project and click on ok and you will see that it got added with jdk 1.8 and all the latest dependencies got downloaded and added from your m2 directory over here directly after that what we have to do is that simple close this particular permit xml file we don't need that so according to the component we have to first of all decide that we have to create a feature file so how will you create a feature file so i'll go to my src test java right click on it and i'm going to create a package over here so let's see this is my uh i would say app a features package that got created click on finish under this particular uh package i'm going to create a file over here let's see my file name is so i simply write okay yeah this is my search dot and guys the extension will be dot feature this is the property of a feature file that it should have the extension dot feature whatever the feature name search feature or a login feature or profile feature that you want to write i can write a simple feature over here so the moment i create service dot feature you can see that one sample feature file got added automatically over here just because of that plugin we have downloaded all these are the commenting sections you can write your author name and list of scenarios you can mention over here and then a lot of things they have given that okay what is the purpose of given some precondition then some key actions then what do you want to do for validation point of view and but also you can add multiple conditions with the help of given when then like that so they have certain given examples over here you can see that one feature is available and then this is my scenario in the form of a given when then and then one more scenario outline we will see in upcoming chapters with examples keyword like that so i'm not going to use these features these are the dummy features i'm going to simply select them and then delete what i'm going to do i'm going to create my own feature so let's see i have one basic feature and my feature name i'll start with a keyword over here i simply write that is let me just maximize it i simply write that okay yeah what is the feature see the moment i write feature colon automatically the color got changed so these are the keywords which are already reserved with cucumber and cucumber will understand these features that you are using it for your creating the feature file now let's see my feature name is let's see uh i want to do some amazon search so i simply write that amazon search over here today i'm not writing any selenium code i simple write some basic java code over here some basic scenarios we will one scenario we will write it over here and after feature guys you can write multiple scenario let's see for basic scenario i'm writing number my first scenario is that this is my scenario name and for this particular scenario what are different steps are available so i'm writing my first step with help of given and i simply write that i have a search field a search field on amazon page this is my precondition that for search a product you should be on the search field on the amazon page then i'm writing when i search for a product with name let's see any name of the product let's see i'm writing for apple macbook a pro over here with name and then i want to write a price also so i simply write then and the price of the product something like this let's see 1000 over here so this apple macbook will be a kind of a string so i'll be writing in double quotes and then thousand let's see thousand dollars i'm writing like uh you know a numeric value so i'm not writing in the form of double quotes then i'm writing then what do you want then when i search the product with a name whatever the name that we have written that apple macbook pro should be displayed let me write it like this so this is a simple scenario you guys that i have created over here according to this particular diagram so this a feature file will be created by the po dev and the qa people and then they will work together and they will write multiple scenarios like that so likewise you can create a number of scenarios okay if you really want to write one more scenario over here you can write it like this scenario number two let's see uh add a product like that so multiple scenarios you can write in the same feature file so let's see today i'm just writing only one scenario so let me delete this so once a feature file is ready you can see that a warning message over here that this step i have search field on amazon does not have a matching glue code blue would mean there is no step definition that you have written all right so now what i'm going to do that i'm going to execute this particular feature file first so how will you execute that you simply right click on your feature go to run as here you will see that cucumber feature when you run it will not see any output over here types so you have to configure this particular feature in your run configuration so simple go to run as run configuration and select this particular camera feature click on new feature and then you have to select where exactly your feature file is available so i'll simply go to browse and where is my feature file is available so i'll uh go to my documents under this particular documents i'll go to that particular project so i'll simply go to just a minute let me go to with a list over here and this is my workspace under this particular workspace this is my project name under src go to test over here go to java app features and the search dot feature i have to select over here and then click on apply and click on run again so guys when you run it you see a message over here on the console that this is my scenario and you have undefined scenarios available over here and it's saying you can implement missing steps with the snippets below so it will give you three java methods over here that given method is not implemented you have the feature but you have not implemented that particular feature so what i'm going to do that i'm going to create the respective step definition right guys so what i'm going to do under my src test java i'm going to create a new package over here let's see my package name is a step and under this particular step definitions i'm going to create a class over here and this is my let's see a search and then here i'm going to create those certain methods right so you can see that given when then we have written and then we have to create this particular and then we have do the mapping over here i can do one thing i can simply go to console and copy these methods from here to here simple copy this and then paste it over here okay now if you notice one thing that it's giving you an error at the rate given so you have to import first of all at the rate given from cucumber or java and then when you have to import again from cucumber.java and then also you have to import from the kimber.java once you import you notice one thing that this is the right given so automatically what will happen cucumber will map this particular given step over here so this given is represented as at the red given annotation over here and whatever the step you have written the step name is i have a search field on amazon page so exact step will be written over here like that and the method name is this so guys here the method name doesn't matter you can write any method name but generally whatever the step name that we have written a cucumber will automatically generate the method name with like this that for after each and every word it will generate one underscore over here so here the method name doesn't matter but this step name whatever the language that you have written the same line you have to write it over here you see that okay i search for a product with name the second step is that automatically it will take that okay yeah we have one string parameter this is apple macbook pro parameter and 1000 is the integer parameter so automatically it will take that okay here you have one string and the price as an integer over here then it's taking as a parameter over here that okay yeah so let's see i'm giving this is my simple product a name an integer i'm writing let's see this is my price so you can change the variable name and you can modify accordingly same thing the product name with a string should be displayed like that step definitions are ready but if you notice one thing that automatically it's saying that throw pending exception because we have not written any steps over here in the form of java code it's simple throwing when java or cucumber will call this particular method it will throw this particular exception so let's run it again and let's see so right click on your feature and then go to run as simple run configuration click on this new configuration this is the project name click my practice feature file and click on run when you run it this time it's saying that your implementation is done but it's giving you the pending exception over here because the first step search a product the moment we execute this particular search or product step over there immediately pending exception will be thrown and your program will be terminated over there that's why you see that okay three steps are there two got skipped and one pending one binding means it's throwing the pending exception over there so what we have to do guys we have to this particular code and then we have to write our own code over here so what i'm going to do is simply remove all these uh okay exception lines and then let's see i'm not writing any selenium code today of simple i'm writing system dot auto twin talent let's say this is my step number one that i'm simply saying that and then i'm writing this is my step number two and simple writing that whatever the name that you are writing the name is what i can append the name with this particular product name whatever the product name that we are passing as a parameter plus and then the price price i'm writing whatever the price that you have written over here okay that you are passing so you can simply see it over here like that so i'll write in the next line so that you will understand better now the third step is that i simply write system dot our pentalen simple so what will happen guys when cucumber will execute this particular feature file this product apple macbook pro will be given to at the rate when this particular method will be executed and the product name is apple macbook pro and the price will be thousand that we are passing from the feature file and it will be given to this particular system.our bin talent or whatever the business logic that you have written over here it will be given to this particular step right so that's why i'm printing the same step over here and the same price over here now i'm going to run it again and let's see it is working or not this time so right click on it go to run as run configuring and simple run now this time you see that all three steps absolutely working fine three quad part there is no exception and you can see that okay yeah this is my scenario search our product i'm on the search page printing it on the console like given uh given i have a search field on the amazon page and the second step apple macbook price is thousand and printing the same thing over here that search for a product with name apple macbook and the price is thousand like that and the third step with product is name should be displayed like that simple so likewise i can see that yes my feature file is ready according to the diagram and step definition is also ready and later on a step definition in the future upcoming videos we will see that how can we create certain utilities and you're calling these utilities from your step definition dot java let's see i'm creating element util.java or web driver or weight utilities or something like this i can call it directly from here now how exactly we can achieve the test driven development approach so according to the bdd we say that okay yeah you have to create the feature first and then you have to start writing your test first time it will be failed and then you have to keep improving the code to make sure your test cases are getting passed and refactor the code and then run it again and make sure your test cases are working fine or not so let's do some uh driven development approach over here so what i'm going to do that i'm going to when i'm on the search page right guys so i'll simply say that okay yeah i don't want to do anything this is just a print statement i want to write but when i come to this particular method i simply say that okay yeah you have to create a product let's say i'm going to create a class variable over here that this is my product and then i'm writing that this product is equal to new product and here i'm passing the same product name over here but here we know that okay we don't have the product class is available the implementation is missing over here we don't have any class for that so what i'm going to do i'm going to create a product class so simple create a class product under my src main java right click on it go to and create a package over here and here the package name i'm going to give that a implementation whatever the package name that you want to write that that doesn't matter and here i'm going to create a product class so let's see my class name is the product and inside this particular product class i'm going to define some implementation so let's see i have one string over here that is uh let's see the product name so i quickly write that yes this is the product name comma and then i'll be writing one integer price over here then i'm going to create the constructor of this particular class so simply go to source and generate the constructor using fields and then you simply click on gen right the constructor remove the super keyword we don't need that and then i'm going to create some getter and setter also if you want to define some values at the runtime you can do that so i'm going to do one thing that i'm going to generate the getter and status generate the getter insider for these two products and then click on generate for these two variables and i make them private so that i can use the encapsulation over here like that so this is the simple method that is written i mean this is a simple class implementation that i have written and inside the product class also i'm going to create one more method which will give me the list of the product so i simply say that okay this method will return the list of strings over here and i simply create arcade that's it that is get product list over here and here i'm going to first of all import this particular list from the java.util package and here i'm going to create one error list the list of a string let's see this is my product list is equal to new error list i'm going to create and in this particular error list i'll be adding a couple of products over here so i said apple macbook pro that's it okay so this is the implementation of the product class that i have created then i'll go to my search steps over here and then this product you have to import from this particular package and then when i search for the product i'll be creating the constructor i mean i'll be calling the constructor of this particular class by creating the object and passing the same product name which i'm getting from the feature file same product name and the price i'm passing it over there and then after that what we have to do after that guys we have to come to this particular method and here the method business logic is missing it means there is no implementation so what i'm going to do that product name a product with name should be displayed it means i'm going to search for that particular product or maybe i have to display that particular product so what i'm going to do that i'm going to create one more implementation over here in the form of search class right so let's see and then i simply write search is equal to new search i'll be writing and but again the implementation is missing for search so i'm going to create one more search class over here in the same package let's see right click on it go to new and create a class over here and i'm going to create a search class and in this particular search class what i'm going to do i'm going to create a simple method over here let's see public display the product something like this i'm going to write and this guy says that okay fine you give me the product name display i'll search and then i'll display the same product name over here what i'm going to do that i simply write one if condition over here and instead of this particular product name this product name is let's see product class of the product name and i simply say that if the product name if the name that you want to give that doesn't matter this is my reference i'm passing the object reference of this particular product name uh dot if you remember this particular method we have written this get product list in this particular list what you contains if you contains whatever the product dot a get product name if it contains it means then you return what then you return the same product dot get product name from here okay else you simple return for a simple write simple return null that's it and instead of void so this is a simple method that i have created i'm passing one product a reference over here i'm getting the product list first of all that this gave me this is giving me the entire list over here and then i'm checking that okay which contains product dot get product name or not because the product name i have already passed from the product constructor and you you can see that okay product name constructor will initialize the product reference very i mean class variable will be initialized and then i'm calling simple get product name method let's see apple macbook pro in this case and the same apple macbook pro will be matched over here it means in this particular product list if i contain that particular apple macbook product you return the same product and then that's it so i'm going to search step.java and then i first of all that i have to import this particular class that i have created and from this particular search reference a dot i simply write my method name that we have written search dot display the product and which product that okay you want to display that the same product okay that we have created the reference over here the product reference so guys don't be confused this is what we have to write the unit level test cases over here and then accordingly we have to uh write our test cases on the basis of my feature file now i'm gonna run it again and let's see what happens so i simple right click on the search dot feature go to run as config so let's see the output and you can see that they are absolutely working fine wow we have written some unit level test cases that i'm on search page search the product with the name apple macbook and the price you can see that okay yeah i search for the product with apple macbook and the price and the product name with apple macbook should be displayed over here absolutely working fine like that okay now if you um let's do one thing that when we search the product this display the product will return a string over here so i'm going to store in a string variable let's see i'm simply writing that is my a product a name is equal to this right and uh product name we have already taken so i'm taking only name over here and then i'm going to print it on the console that whatever the name that you are getting it fine and then if you really want to write an assertion over here that okay assert dot i simply write that assert dot assert equals assert equals what is your expectation my expectation is that from this particular product that you have okay get the product name and what is the actual product that you are getting the same product name i'll be passing over here now you can see that absolutely working fine my uh in the then step i have written that mapple apple macbook is displayed on audience the first product is apple macbook pro and this step is absolutely working fine and all three steps are working fine over here so that is how guys we are using what we are doing first we are writing the feature file and then we start writing the step definition and then we are trying to achieve the test driven development approach over here that at the runtime we are trying to fix our code we are trying to write our test cases to make sure that okay our feature or to make sure that okay our whatever the feature that we have written against those features my test cases are working fine or not so it's very very simple if you really want to practice you can avoid this creating of search product class or the search class and all those things but it's good that okay yeah it's very simple class that i have created don't be confused with that simple getter and setter and one search method that i have created and i'm calling from my step definition the same thing like certain utilities and the implementation classes i can call from a given when then methods and then i can fulfill my requirement over here along with the assertion it's like that so then is generally used for the validation that's why i'm writing one assertion over here maybe this method is deprecated that's why it's saying like that so you can ignore we can uh use some a different assertion over here later on okay now the third thing is guys we have to create a runner.java because every time you can have multiple feature files every time you are not going to right click on a feature file and then run it again and again so what you can do is that you can create a runner file so i'm going to create a separate package for that so let's see this is my test runners and under this particular package you right click on it and create a class over here and my class name is let's see whatever the name you want to give let's see search i'm going to create or you can create let's see amazon test runner that is the better name and you simply click on finish in this particular amazon test runner we don't need to write any implementation we just need to use two important annotations one is run with what run with first of all you have to use a cucumber dot class and the second annotation guys you have to use that is cucumber options and then certain options we have to pass it over here like that so we can write the first option okay so i'll be uh writing like this this is my first option that i'll be writing that where exactly your feature files are available so we have one keyword that is called a features is equal to and where exactly a feature file is available so my feature file is available under over here so right click on it get the properties and copy from src2 okay to the features only so you can directly give the path till search dot feature also but let's see tomorrow you have multiple features and i want to execute multiple features so better to give src test java app features it means under this particular package name we have n number of feature files execute all of them okay and once this is done then put a comma and then the next we don't need to write this bracket over here okay and then we can write that another thing is that is called glue glue defines that with exactly your step definitions are available so we just need to give the package name over here in double quotes so i simply write the step definitions the same package name that i have created it means inside this particular step definitions all these steps are available over here okay and then that's it and then now you have to execute this particular runner file now so let's run it so this runner file will go to the app feature we have this particular search feature.java as i told you it will go to the feature file and the feature file corresponding cucumber will automatically detect that okay yeah what are the different step definition file java classes that you have written and will start executing my java class okay so uh instead of running a feature file i'll be running this runner file now go to run as junit because this is a junit class and you can see that okay amazingly good that all the features are absolutely working fine you can see that okay there are three steps are there i'm on search page and everything and then everything is in green color this is just a logging information you can ignore that and you can see that here the junit plugin also it's showing all this particular search our product that feature that we have written search our product is in green color it means absolutely working fine over here what you can do is that guys that uh if you really want to print a pretty output over here that also you can do that so i'll do one thing put a comma and then we have one plugin of keyword is equal to simple write in double quotes that and in that case you run it again and let's see what kind of output you are getting now you are getting proper output with all the steps over here with colorful steps and everything you can see that okay this is my scenario i'm on the search page and this search page is absolutely working fine in green color when i search for the product it's again coming the green color and then the validation search product is apple macbook pro and this is the output that we are getting it so this is the pretty output that we are getting and absolutely working fine over here like that if you really want to run it from the maven you can run it from the maven also you can directly run from the maven command line or run from your eclipse so right click on your project make sure that may one is installed on your laptop you do want something run as maven test over here and let's see what is output we are getting on the console so here you can see that okay build got successful and then my test cases are working fine over here like that okay if you really want to run um from the command line so let's go to the command line go to properties and copy this particular path let's do one thing let's go to the command line go to the path over here change the directory make sure me one is available on your laptop so i'll quickly check maven version yeah maven is available and i simply write maven a test over here when you run maven test you can see that yeah a build is successful your test cases are working fine over here absolutely fine so if you notice one thing that we are just getting only that the build got successful over here but we are not getting any proper output at which step definition got passed and uh which feature file uh how many steps are there so likewise on the same console also we are not getting any proper output all the build got successful and because of the surefire plugin all my test cases are absolutely working fine but the problem is that what you can do instead of amazon test runner you simply write amazon test because a junit will identify on the basis of this file name that amazon test not on the basis of a runner so i'll just rename this particular file name simple rename to amazon test instead of writing the runner you simply write amazon test or google test like that and then run it again so let's run it again and let's see what happens now on the console you can see that yeah this time it's showing all the reports over here once again let me turn it again that amazon test.java run as not junit we have to execute with a maven so right click on your project go to run as maven test and go to the console now this time you can see that okay it's showing the proper result over here along with all the steps perfect same thing i'm gonna do it from the terminal let me just clear the console and i simply write maven a test now this time and now you can see on the console absolutely working fine with the proper result that build got successful you have one test uh scenario which is absolutely working fine we have zero failures and these are the scenario list over here search your product you can see it over here that search your product i'm on search page and these three steps are absolutely working fine coming in green color like that right guys so this is how you can directly run it from the maven like that so make sure you're writing proper class name over here instead of runner you simply write amazon test over here okay so this is how guys we design a simple cucumber feature file step definition and the runner and then a simple scenario that we have created and executing with the help of runners over here so later on in the next video i'll be telling you that what are the different other examples in are you outline integration with selenium right now i have created one very simple step printing it on the console that's it we are not using any selenium code right now same thing you can do it for your api automation also and you just need to design your feature file accordingly that when i hit this particular post call with this particular url when i pass this particular uh json file or payload then i get 200 response code or like that so you can write an n number of scenarios that doesn't matter either you are writing for the ui automation or api automation or mobile automation unit level test cases or any regression test cases that you are writing matter is how exactly you're creating your scenarios and then converting into the step definition files over here like that so thank you so much guys thanks for watching this particular video that's all for today and in the next video i'll be telling you some more interesting stuff about cucumber please practice and let me know if you have any issues with that thank you so much guys
Info
Channel: Naveen AutomationLabs
Views: 83,851
Rating: undefined out of 5
Keywords: Cucumber BDD, Cucumber tutorials, cucumber BDD with JAVA, Cucumber JVM, Cucumber Ruby, Cucumber with Junit, Cucumber Feature File, How to create a feature file in Cucumber, Gherkin DSL, Cucumber by Naveen, Naveen AutomationLabs
Id: t54-83glFaM
Channel Id: undefined
Length: 43min 56sec (2636 seconds)
Published: Sat Nov 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.