Hello Welcome to Selenium tutorial, Today we are going to discuss how to Execute failed test cases using Selenium
Most of the time we have faced this question in interviews that Can we execute only failed test cases in Selenium or can we identify only failed test cases in Selenium and re-run them.
I really love this feature of TestNG that you can run only failed test cases explicitly without any code. This can be easily done by running one simple testng-failed.xml.
Execute Failed test cases using Selenium
Real-time Example
Take an example that you have one test suite of 100 test cases and once you start execution of test suite there are a number of chances that some test cases will fail.Consider 15 test cases are failing out of 100 now you need to check why these test cases are failing so that you can analyze and find out the reason why they have failed.
Note- Your script can fail due to so many reasons some of them are
1- Some locator has been changed in application because the application is getting new feature- so in this case you need to modify your script in other words you have to refine your script.
You can not avoid maintenance of test script you always have to maintain your scripts 😉
2- Either functionality has been broken- in this case, you have to raise a defect and assign to the respective person.
I have the Youtube video for the same. Kindly check.
Execute Failed test cases using Selenium
Steps
1-If your test cases are failing then once all test suite completed then you have to refresh your project . Right click on project > Click on refresh or Select project and press f5.
2-Check test-output folder, at last, you will get testng-failed.xml
3- Now simply run testng-failed.xml.
How to run testng-failed.xml
We don’t have to perform any other activity once you will get testng-failed.xml double click on this and analyze which test case are failing and why . Then modify your script and run it.
To run above xml simple right click on xml then Select run as then TestNG Suite.
For more info visit TestNG official website
Thanks for visiting my blog. Keep visiting.
Please comment below if you finding any issue. Have a nice day 🙂
Chittaranjan says
Hi Mukesh ,
How can we implement like it will run testng-failed.xml automatically after completion of first suite execution .
Mukesh Otwani says
Hi,
This will help http://learn-automation.com/re-run-selenium-failed-test-cases/
harshal says
if out of 10 testcases 3 are failed. if we run 3 failed test cases after maintance then all 10 test cases will run or only 3. Here execucation of test case3s are depend on passed test cases
Mukesh Otwani says
It will run only failed 3 test cases.
Atitkumar Shingatalur says
When we try to run a test by right clicking on it which is dependent on another test and that test is dependent on another test
Ex: test3 depends on test2 & test2 depends on test1.
So here if I right click and run test3 it will not execute Bcz it has multilevel dependencies.
So my question is when we execute the suite and only test3 failed in that case failed-test.xml will have included only test3. Will it run the test3 alone, Bcz it depends on test2 & test2 depends on test1.
Mukesh Otwani says
Hi Harsha,
It should run all 3 test.
Gaurav Khurana says
Oh thats so easy. If we open that file we can see that just like testng.xml has the configuration to run all cases.
testng-failed.xml contains information for which cases to be run.
First thanks to Test-NG and then to you Mukesh for making things so simple
Mukesh Otwani says
Correct gaurav and I also want to thanks to you to provide always nice comment and feedback.
sujtih says
Hello sriram,
if non of attributes are not available, it is better to goes with xpath or CSS selector.
-Alunkal
sriram says
Hi Mukesh, Thanks for the information.
Could you please help me how we can solve below question.
Q: I have username and password filed and I have only ID or Name something for user name but not for Password. But I want enter the data into password filed how we can achieve this. Could you please help me to slove this one. Thanks in advance.
Siddharth says
Hello Sir,
I am facing problems while using “annotations of TestNG”. I am getting fully confused.
Would you please guide me & Give some examples of every annotations where to use.
So that i can follow those examples for my future reference.
Waiting for your valuable response.
Thanks & Regards,
Siddharth
Mukesh Otwani says
Hi Siddhharth,
I can understand 🙂 will upload an article on this soon.