Selenium Cucumber BDD Framework with Java and TestNG| Run Tests with Maven commands from CommandLine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back I'm Ragin Mishra and I welcome you all in this video we will run our cucumber test with the help of Maven commands so there are two ways to do it one with the help of IDE which is eclipse in our case and second one is command prompt so let us do it so this is my cucumber project wherein I have created the feature file feature file with the tags so I'm going to use these feature file this uh these feature files for my demonstration and I'm going to use this test Runner so that is for the Kumba test runner for the tags so you can see like I'm targeting the tags with a smoke and regression but not in the performance perf okay so I'll be targeting this feature file feature with tags you can see feature with tags okay so these are those feature file okay so I have just mentioned the Gin syntax nothing else so that it will be easier for you to understand and uh this is going to be my test Runner and this is going to be my this for the background and yeah okay so a step definition is nothing but the Step whatever is written over here but since I'm not targeting anything and nothing is written over here so it will not go to that test step definition it is not required okay so let me run it and see how it can be executed okay so first I will run this uh test Runner and see how this program gets executed then I will run the whole project the same program with the help of Maven okay so you can see uh there are two test passed and let us see what are those so if you note down scenario 2 from test feature scenario 2 from test one feature test one feature and scenario 3 from test feature okay so these two test are passed okay so these two test are passed all right so scenario 3 from test three scenario 2 from test one feature all right so let me copy this somewhere to the notepad and then we will see that here I will close it and um all right so yeah this is when we are executing the kukuma test Runner class all alone okay so similarly I should see when I run the with the help of Maven so if you if you have followed my uh previous video you will get to know okay after adding all those dependency in creating the maven project you will see these commands on the uh in context right menu okay so when you click on run as you will see these Maven commands Okay so we will first do the uh Maven clean it will clear all those folders uh for us and then we will run okay we will actually go ahead and do the maven test you have to right click on the project right click and run as and you have to select Maven test okay so you can see these two test whatever we have seen as a stand loone test are actually executed so let me copy this again here okay Maven test okay individual like a stand alone stand alone test Runner file when we executed right Kuma test Runner so which uh targeted the feature file from the specified folder and the step definition of course yeah so scenario 3 from test three and this is second so basically it should all match okay execution whatever whatever we are targeting scenario 2 from test one so you can see a scenario 3 from test three feature and scenario two from test one feature okay got executed all right so this is the time taken uh and let us now so you know right how to run it okay so all you have to now make sure that this particular you know pal XML of your project should have this a couple of plugins installed and let me show you that pal. XML so it may not work you will not be able to see the test uh result like this and uh rather it will only show you the build success but it will not show you the test result like this until you add Maven s fire plugin okay so this is how you can do it let me maximize it and this is what I did so you can go to the maven repository mvn repository and you can download the maven compiler and Maven Sure Fire plugin all right so here right after adding all those those dependencies selenium test NG um sh fire everything right so just coming to the build mavin build you have to add these TXS build then plugins plug-in inside plugins we have to add plugin and inside plug-in we have to give this s fire plug-in and we have to include all the Java when we are including all this Java so it is it is actually targeting the test Runner class in our case okay so this has executed our our uh test run uh test Runner class okay so here everything is done now I can do the same thing uh if I have to enable this other one other test Runner so let me see that yeah you can see these uh so I have enabled this let me comment this out control all I will hold control shift and forward slash it will comment everything and similarly I will comment it out by selecting all control shift and the back slash and I will run it as Maven test again so you can see one more time I will go to the I have just right click in context right click I will go to the run as and I will go to ID you can do Maven clean and then m test I'll just do Maven test and see so this particular you know cucumber feature file is supposed to uh launch the browser okay which eventually is not executing there might be something wrong with the artifactory so let me just Rec uh let me just see this everything is all fine Step definition and uh feature file okay all seems to be good and then I will just right click run as I will clean it first and then I will run it so it is looks like there's something wrong with it but uh yeah did I save it or not so it is targeting oh okay so there is no tag there's nothing with a tag called a smoke so it is it is not executed in so I will just keep it blank okay in this um Runner file I have mentioned the tag is equal to smoke which is why it was not running okay so let me just run it again and uh I'll go to the run as and uh then I'll run it so you can see it is launching the browser entering the username and password and we have seeing our test are getting passed though this error is there so you can just uh uh follow my other video to um uh fix this websocket error that is harmful here so we have executed all our test okay and um this P file got exed executed with the when we run this uh particular you know uh uh test Runner file Kuma test Runner Java it is targeting this particular you feature file which eventually you know um have all the method definition inside step definition inside this particular uh you know file all method got executed okay and you can go to the Target and see the uh output also whatever is there over here okay so HTML report. HTML so this is that you can open that and see that um if particular you know test is passed or not you can see 1 minute ago these particular new test are executed fine okay so I'll close it now um Let me let me just comment this particular you know feature file again and let me just uncomment because I want the test uh to be executed uh the test which has the tag I mean which we have tagged right I want to execute those test okay so I will be using this smoke test because I have kept the uh output of this okay okay so we have already executed let me just run it and see so here you can see everything is fine now okay one test has been executed there is no failure nothing as such okay and this was the test when we executed this particular you know test Runner now we are concentrating on this test runner for the tags okay so the Kumer option you can see these are the tags and the feature file we are uh basically interested in these feature file okay because this feature file we have tagged with the these scenarios with a proper tag scenarios are tagged with the proper tag smoke and regression and perf okay smoke and regression scenario two from test one uh test one feature okay similarly like this and here also we have tagged right so now um we have to exe let us execute it again and then we will move on to the command prompt of uh Maven home and command prompt execution of these test cases okay how to execute these test cases from the command prompt we'll know so you can see the test are matching the result is matching right this is the same result which we have executed scenario 3 from this is scenario particular and the past one is scenario 3 from test three feature scenario 3 from the test three feature scenario two from the test one feature okay so this is uh what we get in the output in the console basically now now if you have to run it from the console I mean command prompt you can go go to the project where the pal is visible okay so let us go to this pal I mean this project uh home basically and quickly check if the pal is if the mavin is installed or not so I will go to the CMD or I can open it from here only okay and quickly see if mvn is installed or not yeah you can see it is installed okay and we can let us check if it shows the version as well or not yeah you can see the version also of mbn so 3.9.5 is installed and this is the maven home which we have set we have installed we have installed we have execute I mean like uh you can simply go to the uh Google and search for Maven download for Windows okay go to the site and get the jip folder so this we have um this you can download and you can set this you can put it in somewhere here I have put it it in here and you can set the maven home like this I'm going to show you the system environment variable for the maven okay so this is how you can set the maven home and set the maven path here okay till bin you can set it I'll cancel because I have already done and I have already told you like how to do it so once the maven is set you can go to the project uh home where your project and your particular file is pom.xml is visible so this is that workspace and palom is visible here so I'm I'm here vdd framework from here you can run your project using mvn clean command I can clean the project directories okay so build is successful you can see the target folder is cleaned and now what I can do I can run the test with the help of mvn test okay so when we pass this test to mvn it is going to execute all those test so it is going to execute my test Runner class okay the way it has executed so you can see the two test are passed okay so I'm going to take the result out here you can see two test are passed this is the result from command prompt CMD okay scenario two from test one test one and three from test three feature just for parity I'm just taking the output here so everything is same right so this is how you can do it and now if you want to override like the tag because there are so many tags right and we are using as per our current test Runner file we are actually concentrating on the tags like this so we are targeting the to execute the feature file which are tagged with smoke and regression but not in the perform okay so let us now override this particular you know setting from the command prompt so I will be focusing on the smoke test okay the test which are tagged with the smoke only so this time result will be different maybe we can see this scenario two from test two feature this time smoke this is now where smoke and do we have smoke only so it looks like only one test case should get executed let us see okay okay all right now how to override that particular you know uh tag so for that we can give mvn test and we can also pass the tag in the as a param okay so how how you will do it cucumber so D cucumber when we are passing uh parameter to the cumber test we are using this minus D and then we use filter then TXS okay and we can give double quote and at the rate whatever test you want to execute so let us see if it is working or not so it is going to Target the feature file or the test which are tagged with smoke okay so you can see it is targeting scenario one from test one feature because it may have the smoke I mean the feature file tagged with the smoke yeah it is tagged with smoke two and uh two test will be scenario will be executed from Fe test one and there is one more from feature file I mean test two feature and there's another one is from feature I mean test 3. feature okay so that is why I mean mavin is executing for project okay so that is how you can play with uh that is how you can you know execute your cucuma test with the mavin commands from the eclipse and as well as from the command prompt so so that's it from this video I hope you have liked the explanation and learned from this video please do like and subscribe to my channel and share it with your friends and also hit the Bell icon for more updates on this channel and also share the feedback in comment section I will see you in next video Until then keep learning and thanks for watching
Info
Channel: SDET Adda For QA Automation
Views: 2,759
Rating: undefined out of 5
Keywords: How to run Cucumber Selenium from Command line, Use Maven Build Plugins to execute cucumber tests, Running Cucumber Tests using Maven, How to Run Cucumber Test as Maven Test, how to run cucumber tests from command line with tags, Maven Test run from Eclipse, mvn test command from command line, Maven surefire plugin integration with Cucumber BDD TestNG, Run Feature Files from Maven Test, Running Cucumber test with TestNG, How to Run Cucumber Tests with Maven, bdd, cucumber, webdriver
Id: rXEuBelQLFA
Channel Id: undefined
Length: 19min 16sec (1156 seconds)
Published: Fri Oct 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.