How to Run Cucumber Test as Maven Test

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey hi everyone welcome back to another video on cucumber in this video we'll mainly discuss how we can run cucumber test as a maven test so as we know Maven is a build tool so end goal of uh our automation is we have to execute as a maven build so I will show you what are the things you need to change in your pom.xml file so we'll configure We'll add C fire plugin and compiler and then finally we will specify which test Runner we have to execute so let's go back here this is the pom.xml which we have created can uh previously I was using Eclipse Luna so recent uh just before this video I updated to Eclipse mask so I'm using the latest one if you still using 4.5.2 it's fine I'm using 4.5 so right now it's showing this cross symbol it's just a update issue so simply right click Maven and update project and click on okay so internally if there's something wrong it will fix automatically so this is our previous test Runner which we uh which we have written last time and this is the step definition and this was of a feature file so in last video we already covered this data driven test so let's say I want to run this trust Runner as a mavin build so what are the changes we need to do so the you have to install certain plugins so build is a separate tag which you need to add build will start build with with uh end now we need first plugin that is Maven compiler plugin then we need a Movin sh fire plugin and then we have to specify which Java file you want to execute so let me copy this complete build from here and I will go to pom.xml file and after the dependencies I will right click here and I will uh say show line number it will be easy for you so now simply uh control V so it says build will start build with end we need two plugins so first plugin is this Maven compiler plugin the second plugin is Maven sh fire plugin this plugin will actually will execute your Java file so here we need to execute I will specify please run runner new. Java so if you see Runner new. Java so what is this uh double star double star means in the project directory whenever uh it will find the complete project and any file which contains Runner new. Java it will execute so this is the wild card so the first two double star will check the complete project and in any project or any package if it is finding any class which is ending with Runner new. Java it will execute so simply control s so it will start downloading the plugins if required and once we are done this is the po. XML file now if I go to my uh step definition here I'm using Firefox and every time it Waits so I will use it Chrome driver I want to use the Chrome now so Chrome is little bit faster as compared to Firefox so I will add this chrome driver and I will add the property so if you are not familiar with how to start with chrome you can check my previous tutorials so here I will mention web driver. chrome. driver and here we need to specify the Chrome driver path so I already have I driver Chrome driver in a separate directory so I will only get the path from here okay so yeah just one more yeah so now we are done our test will will run on Chrome now so if I execute this so if I run this test Runner it will simply execute in a normal plain Java mode but let's run this in a maven style so let's run as first I will say Maven CLE so it will clean my target directory so yes MAV started build success and it has deleted the target directory now let's run it and let's say run as Maven install you can directly say Maven test but I will recommend you to go with Maven install so what Maven install will do it will check if any files are missing it will install the necessary plugins or any file then it will start with your regular test so changes detected recompiling the module fine and it has started so it says I'm running runner. testr runner. new so this this is the runner package which it is uh running and the class name is test Runner new and you can see Chrome is started and remaining test will be same because we are not changing the execution we are only changing uh from traditional Java execution to maven test execution so rest of the code will remain same so let's wait since I have given three times so it will execute the code three times so I'm still using the previous uh Chrome version that is 2.20 if you want to use the latest version the latest one is 2.20 or 2.21 so if you want to update simply go to S match.org SL downloads and uh you can find the latest Chrome driver over here so if you go to yeah this is the one third part yeah so latest is 2.21 I'm still using 2.20 so this is the last execution and yeah we are done so once your Maven build is success okay it's a build success and uh you will get the same thing three scenarios executed and 12 steps and if you refresh you'll get the target HTML reports this is the report which we want web browser and now if you go to any normal browser and check the same old report that we have done in the data driven test with three different p parameters you can see for running as a maven build you don't have to do much only you need to add the plugins and you need to mention which file you want to run so right now we have only one test Runner you can have multiple test Runner and you can execute multiple test runnner through this pom.xml as well so right now if you noticed uh I manually changed the browser here right but I want to keep it little bit Dynamic like based on the browser uh it should start my session so in the next video I will show you how you can create this test little bit Dynamic so I will pass the browser from the command line or you can say from this feature file so based on my yeah so this is the hardcoded thing right here I have to change it to the dynamic like based on the browser it should start the respective browser so that we'll see in the next video uh stay tuned I will continue with the same project again it's showing the cross mark so don't worry just go to this MAV option and say update project and it will resolve your issue yeah that's all I have for this soon we are going to integrate this Maven project through genkins so when you execute any Jenkins job it will execute your cucumber test that's all I have for this video thank you so much have a nice day
Info
Channel: Mukesh otwani
Views: 62,557
Rating: undefined out of 5
Keywords: Selenium, Cucumber, Automation, Maven
Id: 4cF1Q7CISSE
Channel Id: undefined
Length: 9min 6sec (546 seconds)
Published: Mon Jun 06 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.