How to run failed test cases using TestNG in Selenium Webdriver?
On This Page Introduction to TestNGWhy TestNG?April 20, 2026 · 5 min read · Tool Comparison
In every software testing summons, there are unavoidably times when tryout cases miscarry. Test suit unremarkably fail due to server and meshing number, an unresponsive application or validation failure, or even due to scripting topic. When failures occur, it is necessary to cover and rerun them to get the craved yield. An efficient way to do this is to use the TestNG suite. Why Test Cases Fail? Network/server issues • Application unresponsiveness • Validation failures • Scripting errors Benefits of Using TestNG with Selenium How to Run Failed Test Cases in TestNG? Advantages of Rerunning Failed Test Cases This clause will delve intohow to run failed test cases in TestNG using . stands for Test Next Generation and it is an open-source enliven by. Think of TestNG as an upgraded adaptation of the early two frameworks. It ply additional functionality such as test, grouping,, parameterization, and sequencing proficiency in the codification & # 8211; features that were not cater earlier. TestNG framework not only manages test instance but besides provides detailed account of those tests. It provide a detailed summary that displays the turn of test cases that experience failed. The report too enable tester to accurately situate glitch and fix them at the earliest. Also Read: TestNG offers the following features: SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. Before proceeding with this article, receive a looking at this which discusses how to execute test cases using this framework. First, let ’ s create a elementary java project and write test cause. Next, create 3 class files as shown below. Also Read: Also, make sure to configure. The examiner, in this exemplar, has written unproblematic examination cases in all the 3 class files as shown below. Test1.java Test2.java Test3.java Test1 and Test2 will work fine without any fault. In case of Test3, the tester is purposely try to make the test case to miscarry in order to showcase how to run failed test causa. Therefore, the code include@ Asert.assertTrue (mistaken);to neglect this exceptional test case. Save all these test instance. Now, go to theproject folder & gt; right pawl on the projection & gt; Choose TestNG & gt; Convert to TestNG. The snapshot below depicts the same. This will automatically yield atestng.xmlfile as shown below. Now, detent on thetestng.xmlfile and run as& gt; TestNGSuite. Refer to the snapshot below. Output goes as follows: As shown, there is one failure in the full run. It is leisurely to go back and check the class files manually to understand the error as there are alone 3 test cases. But, when there are thousands of test cases, checking class file manually and so resolving the errors is time-consuming and tedious. Hence, it is necessary to use TestNG to identify failed test cases and re-execute them. Run Selenium Tests for Gratuitous Right pawl on the project and choose Refresh. On refreshing, the tester will see a test-output folder as demo below. In the testng.xmlfile, the suite name is Suite. Therefore, in the above snapshot, there is a folder calledSuite.Expand that to get a file calledtestng-failed.xmlas shown below. Contents of the testng-failed will be as below: It clearly reference that Test3 has failed. The examiner can too view the HTML representation of the Test as present below: This clearly shows which test lawsuit failed. Let us next see how to rebroadcast failed test cases in TestNG. Go rearward to Test3,modification the assert value to true and rerun the testng-failed.xml file.This will execute only the failed exam case with the correct output. In order to cross-check, execute the originaltestng.xmlfile and check if all the test case are working as expected. As this article explains, it requires only a few stairs to rerun failed test cases with TestNG and Selenium WebDriver. Run the code, evaluate the resolution, and start streamlining machine-driven website tests with and TestNG. Needless to say, these tests are incessantly best run on real browsers and devices. BrowserStack proffer a of 3000+ real browser and devices, which tester can access to runSelenium tryout. Simply sign up, opt the browser-device-OS combination ask, and. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How to run failed test cases using TestNG in Selenium Webdriver?
Overview
Introduction to TestNG
Test Management Reimagined with AI
Why TestNG?
How to Run a Failed Test Case using TestNG in Selenium WebDriver?
package testngtest; meaning org.testng.annotations.Test; @ Test public family Test1 {public void testwhatsapp () {@ Asert.assertTrue (true); System.out.println (`` Whatsapp is working fine '');}}package testngtest; importation org.testng.annotations.Test; @ Test world class Test1 {public vacuum testlinkedin () {@ Asert.assertTrue (true); System.out.println (`` Linkedin is working fine '');}}package testngtest; significance org.testng.annotations.Test; @ Test public class Test1 {public nullity testgoogle () {@ Asert.assertTrue (false); System.out.println (`` Google is work okay '');}}How to Run Failed Test Cases in TestNG?
This test-output folder comprises various files that include failed test cases as easily. See below.& lt;? xml version= '' 1.0 '' encoding= '' UTF-8 ''? & gt; & lt;! DOCTYPE suite SYSTEM `` https: //testng.org/testng-1.0.dtd '' & gt; & lt; suite guice-stage= '' DEVELOPMENT '' name= '' Failed suite [Suite] '' & gt; & lt; test thread-count= '' 5 '' name= '' Test (failed) '' & gt; & lt; classes & gt; & lt; stratum name= '' testngtest.Test3 '' & gt; & lt; methods & gt; & lt; include name= '' testgoogle '' / & gt; & lt; /methods & gt; & lt; /class & gt; & lt;! -- testngtest.Test3 → & lt; /classes & gt; & lt; /test & gt; & lt;! -- Test (failed) → & lt; /suite & gt; & lt;! -- Failed suite [Suite] -- & gt;
Related Guides
Automate This With SUSA
Test Your App Autonomously