PART 5 - Run Cucumber Feature Files in Parallel Mode using Maven Fail Safe Plugin & JUNIT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is nadine welcome back to naveen automation labs so in this particular cucumber video guys um we are going to cover how to execute the parallel testing there are some challenges we know that with cucumber with respect to parallel execution but there are certain solutions are available the first solution i'll tell you with junit and what exactly i'm planning for parallel execution i'm planning to cover in multiple sessions so today we will see that with the help of one maven plugin how can we execute how can we execute the test cases in the parallel mode one thing you need to remember guys that we are using junit if you see our format xml file we are using cucumber with a junit and my test runner is also available with the help of junit only you can see that we are not using testing g although you can use cucumber by testing g and then you can do better parallel execution with test ng but the limitation with the cucumber with j unit according to the documentation and i've practically seen that number of a feature file will be executed in the parallel mode so let's see we have two feature files are available over here two threads will be working okay one by one on these particular features file it means one thread will pick this guy and second thread will pick the second feature file it means we can achieve the feature wise parallel testing feature file wise panel testing we can do that with the help of cucumber junit right but if you have let's see in your login page over here we have three scenarios are available these three scenarios will be executing on the same browser it means they cannot be run in the parallel mode the feature files will be running in the panel remote same thing let's see if you go to accounts page we have again two scenarios are available so scenario number one and scenario number two will be executed on the same browser right so you can say that okay login page will be running on a different browser accounts page is running on a different browser in the parallel mode at the feature level not at the scenario level that is a limitation with the with cucumber with junit but same thing we can solve this particular problem with the cucumber with sng maybe i can cover in upcoming chapters this is the first thing second thing is that guys the problem is if you really want to run on the cross browser testing right that time we can do that for sure with qmi junit but we have to maintain our feature files accordingly for example we have to pass the browser property over here that something over here we have to add one step your login page title run execute this particular application and launch the application on google chrome or firefox so we have to maintain the scenarios in multiple feature files like that so that also i'll show you in the next video that login page feature with chrome and with firefox so we have to maintain uh two scenarios uh feature files over there like that okay because it's slightly tricky to achieve the cross browser testing also because the problem is if you go to our hooks application hooks here we have getting the property from my config.properties over here where which is available over here browser equal to chrome so either we have to maintain multiple browsers over there and we have to write some custom logic over here but how will you distribute the thread over there that is the biggest challenge but same thing we can solve this problem with the test ng but in junit how to do that with the help of multiple features browser wise we can do that so we can create multiple packages over here let's see the package number one for uh chrome package number two for firefox like that also we can maintain that some people they maintain like that but in this particular video i'm gonna show you how to achieve the parallel testing on the same browser let's say i want to execute these two feature files on two google chrome because we are maintaining chrome over here right like this you can change it to firefox also and then accordingly in your application hooks uh we are calling this particular initialize driver method and then firefox also we are maintaining it so we will see that can be run on multiple firefox as well so how to do this so first what guys you have to open your powered xml file and you just need to add one a couple of plugins first of all that please add your compiler plugin so that we can achieve the complete maven uh lifecycle then add this a surefire plugin so that you can it's not that important and third thing is that you have to add this maven failsafe plugin over here you can check the latest version of this but i think this is the latest version you can use that and then in this mail save a facelift plugin what exactly whatever the goal that you want to write that okay whatever the name integration test or sanity test or whatever you want to write you can do that and here you have to give the path of your runner.java that you have created over here so that we have already created my test runner dot java where the feature file path and the step definition path that we have already given and then here you see these are the three configuration important attributes are available parallel equal to methods you can write parallel equal to classes also thread code is equal to four it may generate four thread counts at the same time and per core thread count is equal to a true it means per core thread count i want to maintain you if you want to make it false also that also you can do that but make it true so that we can achieve the cpu core for per thread count over there right that's it after that you don't need to do any other thing make sure that okay you are including your my test runner a dot java over there and make sure that okay you are giving the relative path like that and do not give the hard coded path and add this particular plugin and that's it after that what you have to do you have to execute it either from eclipse or let's go to the maven properties let's go to the properties copy this particular command sorry this particular path and go to your terminal so i'll go to my terminal and just clear the console go to this particular directory and just need to execute this particular command maven verify and then enter and let's see what is happening with maven verify so it will compile the code it will reach at the test level and then we will see we can see that browsers are running two feature files running in the panel mode you can see the two browsers are running in the panel mode right because we have two feature files so at a time you will see two browsers over here you can see that these two browsers are running in the panel mode race see this so execution is happening absolutely fine like that and then finally it will generate the report so we have to make sure that with parallel execution my report should not be yet disturbed so let's do one thing uh go to the terminal and yes build got successful out of five test cases one got failed obviously that forgot password the locator that we have already changed so that i can generate the screenshot in my report so deliberately i'm making it fail and you can come over here you can see what exactly the reason behind that and which step got failed and the report got generated over here so this is the cucumber report got generated and i'll go to my browser over here let's type it and then see this report yeah 80 test cases got pass uh an account feature i don't have any issue you can see that it's perfectly fine and then the login feature we have this forgot password step got failed so this scenario overall got failed this is the reason behind that and this is the screenshot that we have it and the last scenario is login with correct credential everything is getting passed over here so this is the web cucumber ui report is coming perfectly fine and in the last video also i told you that spark pdf report and html report so right click on it and go to simple refresh and you will see that automatically one test output folder pdf report make sure it's generating yes this is also absolutely fine you can see that right now the time is 9 51. here also you can see that we executed at 9.52 i mean right now it's 952 or 251 whatever it is the same time and report everything we are getting it and one test got failed over here the failure one is the forgot password link so my pdf report is absolutely fine let me just close it and then check your index.html also that is the spark extent report so simple go to you can open with the you can copy the paste copy the location and then simply use the web browser also you can use in your eclipse and you can see that okay yeah it's 9 51. check the failure report you can see that come over here and then see the screenshot is available over here perfect and account page is absolutely working fine everything is fine account based section count everything is in green color like that so the reports are absolutely fine you can see the timing also 951 perfect now one more attribute you can add in your if you really want to see that panel execution actually happened or not so what exactly you can do you can go to your my tester network java and add one more plugin over here put a comma and simply copy paste this particular plugin that is called timeline plugin and i want to generate the timeline html report for my threads so how many threads actually participated we have two feature file so two threads okay were there and uh generate that report some folder you create test output hyphen thread let's see i have created and put a slash over here so it in this particular folder automatically one index.html file will be created and you can see your threads over here that in in that particular pool how many threads were there and which scenario were executed by which thread right so let's see how exactly the thread kind of report a thread based report is coming or not so right now you can see that okay i don't have any uh test output thread folder whatever the folder name you want to give guys you can give that so let's run it once again from the maven and run with maven verify make sure a1 is installed okay on your system then only you can execute these commands otherwise you can directly execute from your from from eclipse also you can do that but you have to use maven verify do not use maven clean install you have to use maven verify command over there so let it run you can see that parallel execution is happening absolutely fine okay almost done yep so this is let it complete it's saying pdf report configuration.pound that's fine configuration is not found that's okay that's just a warning and now everything is fine build got successful one got failed now let's see this report once again right click on it on your project and simple go to refresh and now you see that ok test output folder test output folder for spark report got generated but you see this time test output thread also got generated having some different js and other css files copy this index.html right click on it go to properties copy the path of this index.html and open in a new tab and paste it over there and then see this report awesome right this is also available in the documentation you can go and check it over there you can see that in the thread pool number one thread number one executed all the scenarios from the accounts page feature file this is account page feature and account page title is a scenario number one account page feature account section count scenario number two and then in login we have three scenarios number one two and three like that and you can see this scenario is actually coming in red color because it got failed and you can pick the scenario name from here as well you can see that and the moment let's see you forgot password it will highlight a specific scenario over there like that it's giving you the time is uh 21 55 22 december and two rows mean two threads were there you can see that pool number one thread one uh got participant main thread executed this particular account page feature like that right you can uh match in account page we have two scenarios see this scenario is account page title and account based section count same thing you can see account page title and account base section count so as i told you with this particular configuration that we have used okay it will execute the execution it will do the panel execution feature level it means multiple feature files you can execute in the panel mode okay not at the scenario level now what i'm going to do that uh let's do one thing it's quickly checked with the firefox also so i'll quickly write it to the firefox i hope firefox will be launched because we have written the logic i remember that we will go to the initialize driver and if it is firefox it will launch the firefox and it will set the thread local driver with the firefox driver so let's see it is coming or not so let me clear the console and go with maven verify and let's see two firefox should be launched okay it's trying to do something yes something happened okay yes okay firefox are getting launched you can see that yeah this is also going good okay great awesome but one problem i noticed that because we have given the count of thread count is equal to four so these two firefox are unnecessary uh you know just blank firefox got introduced so i need to check this particular thing because at a time we are using only two feature files only two firefox should be launched but see these two firefox are blank and other two firefox they execute the uh code and then they are done but they are still running in the background but anyways we can see that yeah this is absolutely fine and then you can see the report once again over here just simple refresh let's and yeah so this time it's saying account page got failed login page also got failed with forgot password and login page title maybe because of that particular firefox thing but it should run fine um we need to check this maybe browser equal to firefox i'll check it and you guys also check it once let me just close this particular mozilla and this and let me just clear the console and let's try once again may one verify okay this time it's running with two firefox okay the outside thing fits fine you can see that two firefox i don't know what happened with the first time perfect now it's absolutely fine guys so great see you can see the panel execution running in two see two executions that are happening one is for feature one is for login feature and one is for accounts feature great awesome perfect great so now we can see the thread report now this time thread report is absolutely fine maybe some glitch earlier four threads unnecessary i mean four browsers necessary called xe unit anyway that we can ignore that part so this is with firefox also which is absolutely working fine and you can write your other browsers also you can do that okay now what i'm going to do that i'll go to config.properties and make it back to chrome only now one last thing we can do is that just to make it more clear that it's actually running in okay on the basis of the feature files that you have created let's do one thing let's create one more feature file and create a file over here let's say i'm just simple giving acc dot feature right and whatever the steps that you have written already in account feature copy these steps and simple go to acc dot feature and paste it over here right the steps definitions are already written i just created one duplicate feature file so how many threads should be there at a time three threads it means three chrome browsers should be running at the same time right so let's see this time what is happening because we have to check that okay feature file exec panel execution is actually happening or not so yes it should pick awesome this is what i want see this three panel execution ways three browsers and three panel execution like that great so this is absolutely working fine although we have repeated the feature that's okay you can create let's see for some other page also you can create a feature file at that time and then accordingly you can practice so i really don't want to spend time on creating one more feature file and creating the page object once again because those things we have already seen that now and now the report is done and let's see the final report yeah so this time uh yeah build got successful one got failed that's okay and uh let's copy this particular ui report first and first of all let's see the thread count so you can see three threads are there awesome one is uh you can see for accounts page we have two feature files are available and login page we have one feature file is available like that so in three threads thread number one two and three participated for this execution you can search for the tag also right now let's see we have only account stack and then it will show you the accounts tag only and if you uh just reset that it will show you all the links and you can puff you can select the specific scenario name also you can select that now let's see this particular report i'll simply uh copy this guy from here to here and the web report is also perfectly fine you can see that three feature files acc dot feature login page dot feature and account space dot feature which is absolutely working fine like that so three feature files got executed in the parallel mode guys this is what we have learned today so please do this experiment and uh try this thing if you're using junit and i'll prepare one more video for the cross browser testing with the pal execution with junit and then the third video i'll be preparing with test changing right give me some time let me do some experiment and then i'll show you the perfect uh execution over there perfect uh configuration over there so that's all for this particular video guys it's very quick thing no big deal and i'll be uh i'll be uploading this particular code right now so let me just go to the terminal you can find this particular code to the github so let me just check the status we made couple of changes over here so i simply write git add space dot uh get commit minus m and then i simply write that okay l added j unit parallel execution uh maven plugin done and then after that get push origin master now you can see the code code is available in my git repository and you can find the repository url in the description of the video or you can just directly go to naveen automation labs on my github page and the code will be available over here you can clone this project and see uh 24 seconds ago we updated this and pubmed xml file you will see this particular plugin over here like that start using it and then enjoy your parallel execution that's all guys thank you so much thanks for watching this particular video please subscribe to the channel if you haven't yet and please share with others who are actually looking for the cucumber latest videos and let me know if you have any questions and let me know if you have any certain other solutions also for fan execution i would happy to hear you guys thanks a lot guys keep watching naveen automation labs
Info
Channel: Naveen AutomationLabs
Views: 24,642
Rating: undefined out of 5
Keywords: cucumber parallel run, cucumber selenium, cucumber extent report, cucumber 6 with extent report, cucumber spark extent report, cucumber spark PDF report, cucumber with selenium, cucumber HTML Report, Cucumber Web UI report, cucumber tutorials, cucumber BDD framework, cucumber 6 latest videos, cucumber by naveen, Naveen AutomationLabs
Id: yxBivjMrbPo
Channel Id: undefined
Length: 20min 13sec (1213 seconds)
Published: Tue Dec 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.