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

How to run failed test cases using TestNG in Selenium Webdriver?

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.

Overview

Why Test Cases Fail?

Network/server issues • Application unresponsiveness • Validation failures • Scripting errors

Benefits of Using TestNG with Selenium

  • Leisurely group of tests viatestng.xml
  • Cross-browser test support
  • Unseamed integration withMaven, Jenkins, CI/CD pipelines
  • Auto-generated reports for faster debugging

How to Run Failed Test Cases in TestNG?

  • Execute trial suite → failure get logged automatically
  • TestNG create atestng-failed.xmlfile insidetest-output folder
  • Rerun solely failed case by executingtestng-failed.xml
  • Update assertions/fixes → re-execute originaltestng.xmlfor proof

Advantages of Rerunning Failed Test Cases

  • Saves time in big trial cortege
  • Eliminates need to re-run all tryout
  • Provides quick validation of fixes

This clause will delve intohow to run failed test cases in TestNG using .

Introduction to TestNG

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:

Test Management Reimagined with AI

Join our live webinar to discover how top QA teams boost trial conception swiftness by 90 % using AI.

Why TestNG?

TestNG offers the following features:

  • It generates the report in a proper formatting that includes the number of test cases fulfill, the number of failed test cases, and the test cases that receive be cut.
  • Multiple test cases can be grouped easily by converting them intoTestNG.xmlfile. Here, set the anteriority to execute test example.
  • Using TestNG, one can execute multiple test suit on multiple browsers, i.e.,.
  • The testing framework can be easy incorporate with tools like Maven, Jenkins, etc.

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.

How to Run a Failed Test Case using TestNG in Selenium WebDriver?

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

package testngtest; meaning org.testng.annotations.Test; @ Test public family Test1 {public void testwhatsapp () {@ Asert.assertTrue (true); System.out.println (`` Whatsapp is working fine '');}}

Test2.java

package testngtest; importation org.testng.annotations.Test; @ Test world class Test1 {public vacuum testlinkedin () {@ Asert.assertTrue (true); System.out.println (`` Linkedin is working fine '');}}

Test3.java

package testngtest; significance org.testng.annotations.Test; @ Test public class Test1 {public nullity testgoogle () {@ Asert.assertTrue (false); System.out.println (`` Google is work okay '');}}

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

How to Run Failed Test Cases in TestNG?

Right pawl on the project and choose Refresh. On refreshing, the tester will see a test-output folder as demo below.


This test-output folder comprises various files that include failed test cases as easily. See 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:

& 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;

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.

Tags
43,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free