How to execute failed test cases in Selenium webdriver

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone this is mukesh from blonde - automation comm today we will mainly discuss on the test in g part and the main topic for today is how to execute only the field test cases in selenium-webdriver so this part is to test in g so let me show you what exactly you will get after this video so today we will discuss why generally our test script will fail generally not only with selenium you will get the scenario with every automation tool so today we will discuss the possible scenarios wire generally the test script fails then we will talk about how to run only the failed test cases manually so using eclipse we can execute and the most interesting part which I can guarantee no one has covered till now how to execute the field test cases using a plain Java program so let's get started with the first one why test fails sometimes let's say you have a bunch of test cases let us say 100 test cases and out of 100 90 is passing but 10 is failing so it's not mandatory all the 10 test cases failing just because of a scripting issue it there can be the multiple issues so some time application is down sometimes server is not responding like you are not getting the enough content all it say the page is not rendering properly some time network issue so sometimes your Wi-Fi or LAN cable is not working properly so it is not a scripting is just a network issue yes sometime it is a scripting issue so you need to rectify your script you need to identify generally a scripting issue you can say the locator has been changed or you have not handled any scenarios or lets stay any sync issues so if it is scripting issue you need to fix it and run it again and finally application issue let us say you are executing your test in some validation field and it's a real application issue then in case you need to talk to the respect to developer or maybe can directly raise a bug so it will be added advantage for you so you can see in all these scenarios you need to rerun your test cases it does matter what is the exact reason but you need to run your automation scripts so now you have two ways either identify the field test cases and run them but you will get a separate XML today which will only contain the field exfil test cases so you need to simply execute that XML so let me show you yeah so let's this is our project let me create a separate package let's say test in G gauss's let me rename it test ng classes let me create one test case now let's it test one let us set this case one it makes motions so let us say I have one test case here so let me give a dummy test case name that is a test Facebook and here I will simply print one like Facebook is working as expected and I will surround this with a notation test and I will import this test in G now if I write the selenium script this will take some time so as of now I have simplices out a statement here I will not rewrite the complete selenium code because the main idea of this video the main logic which I want to show you how you can run the field test case so I will create three test cases and one test case I will fail about maybe two so let's copy-paste and I will say test case two and in test case - I will say test Twitter so this is also fine let me create one more test I will copy and paste here and this is test case three so now I have third test case let me change it to test WordPress so now I have three test cases and let me fail this test case forcefully so I will use assert and use assert of testing G so sir dot assert if you are not familiar with assert then please check out my video assertion in selenium so in a certify pass false condition this will fail my test so I am just failing this forcefully so that I can show you how to execute failed test cases so I have three test cases test case one will pass test kiss too will pass because we have simplicious out a statement here this case three will fail because due to some assertion and I did this forcefully so now if I want to create an XML file so let us right click on this package you will get this option called test in G convert to test in G so let me show you something let us rename it you can see one location by default it is going to the project home directory let me rename it to smoke test dot XML you can keep it as it is it will no it will be like same but I generally rename it so that I can relate easily and sweet name I will give smoke test scenarios and here I will give as sprint one so you can see water changes we have done here it's simply reflecting here and I will simply click on finish so I got this XML if I simply double-click on this XML file this is the design part I am NOT interested in design let me click on source so this is same XML here whatever changes we have done sweet name is smoke test scenarios this test name is print here we have three classes is 1 2 3 if you want to arrange them in order so this is the exact order now if I will run them so simply right click on this XML run as test ng suite so as expected yes if you see three scenarios we executed one failed so fweet it is working as expected and if you see this graphical representation to test pass 1 fail so now how you will identify so either you go manually and check ok this test is running go and individually run this test so right now it looks quite easy because we have only one field test case so let us see you have 10 or 15 test cases or let's say 20 then you cannot run them so either create again one more XML file and run them but this is done automatically handled by test ng so if you simply refresh your project you will get this test folder if I open this so you need to check here now if I go back to the XML which we have created the suite name which we gave smoke test scenario right so you can see it has created a folder over here and if I expand this you can see the sprint 1 so sprint 1 dot HTML is created so test Angie will generate report into format 1 is the HTML format which is this let me show you in a browser and another format is XML format so if you can read this XML format because it contains the same data which we are getting in browser this is low because a to test case pass one failed due to the assertions that's fine now if you go back here you will get another report in XML format if you want to see so let's open with XML editor you can see it's weird right but if you check closely it gives me some internal information about my system which is the host how many test cases at what time executed so everything which we are getting on HTML it's giving an XML format I am NOT interested in XML so I will simply go back here now if you notice we are getting one more XML file called test in G - failed or XML so this XML will only contain the information about the field test cases so if you see here it is equal to the same which we have created now the suite name which it has been created like sprint one field which test case is failing so it is failing test case C and which method is test WordPress so it contains the information about the failed test cases so now if I want to run this I will simply right click run as test in G suite and you will notice it will run only one because only one test is failing so what I will do I will quickly go here and if I simply change it to true my test should pass so if I right click and before running this now if you simply refresh this ok so you can see here I am getting one more fold let me close the necessary VIN do it it will confuse you so you can see we are getting one more folder now fail suit so if you run the test and you failed at XML it will create another suite for you that is fails it and you will get the failed test cases report only so let's yeah so now we have done the changes so if you run this test and you failed load xml again your test will pass okay so WordPress working as expected so this is one way another way is using programmatically because every time now if you see the problem with this approach I cannot go manually right leg and run as I want a smart way like whenever my test case is failing I should trigger another program which will check if this filtered XML is present then run this so how can we do this let me show you so let me give a false value away and let me close all the necessary windows so let me create another package now and this package name I will give as a runner I will create a test runner here today and this test Runner class will be responsible to execute the failed or taxable I should have taken the public static void main but it's okay let's write it manually so public static void main so today we will introduce another class of testing G called testing G itself so simple type testing G test or let's say runner equal to new testing G so till now testing G were using only for annotations right but actually it is a separate class indistinct packet so if you put mouse over here you will get option to import this test in G so now guys you need to be little bit careful here because same class is present under comm dot B you stood or testing G and the same class is present under waajid or testing G so let us take the first one so this Runner have one method call set test suite so you can see the second last option set test suite like whatever test suite you will specify it will simply run them but as we can see it is expecting a list you can see it is expecting a list of test Suites so what we need to do now we need to create a list now list of a string so this is how we do so if you are new with this feature then you need to refer one java topic called collection so this error list unless these are coming from the Java dot util package and as of now you can consider this as a dynamic array so whatever test Suites let us say you want to execute five six so at runtime it will take the list so let us import them list I will import from Java dot util not from java java dot AWT same thing i will do for ArrayList i will import from Java dot util so now I have this list object so what I will do I will add the XML file which I want to execute so in my case it is located under smoke test in areas and destiny field dot XML so I will try click on this and this is the complete path which I will simply paste and let me give one backward slash again for everything okay so now you have this suite ready and you need to pass this list so now we have done the set test suite finally you need to say runner dot run so run is the actual method which will execute the test so let me explain this code again we have created object of test in G class then we created list of string so in this list you can add multiple XML file but in this demo I'm only giving one XML file this pass this list through this method called set test suite and finally than this so if you simply right click run as java application so you can see it is running the same suite which is getting filled right so right now i'm not simply going to the xml par xml file run it and run s testing suite we have created a small program now this program will always check if this file is present it will simply run this xml otherwise it will skip so if you want to implement this in your framework it would be good because it will help you to read in your tests so let us assume after reason also it is failing then you need to check the exact issue because sometime ririn will help you but if it is failing every 10 then you need to check what is the exact root cause of the field test cases so that's all i have for today so if you go back we have covered everything so if you still have any doubt you can drop me an e-mail or and the complete code you will get in the description so I have written the same article so just go to the description if you want to check more details thank you so much have a nice day
Info
Channel: Mukesh otwani
Views: 83,142
Rating: 4.9465718 out of 5
Keywords: TestNG, Selenium, Automation, Failed Testcases
Id: kaUJgNyLaKs
Channel Id: undefined
Length: 17min 8sec (1028 seconds)
Published: Tue May 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.