• What is Automation Testing - Advantages & Types of Tools
  • What is Selenium IDE, Selenium RC, Selenium WebDriver, Selenium Grid?
  • Selenium IDE, Firebug & Firepath Installation


  • Selenium WebDriver Architecture
  • Selenium Installation
  • Challenges and Limitations of Selenium
  • First Selenium WebDriver Script
  • Working with Firefox Browser
  • Solution - Failed To Launch Browser Using Selenium WebDriver
  • Working with Chrome Browser
  • Working with IE Browser
  • Difference Between FindElement & FindElements
  • Install Firebug, Fire path and other add on for Selenium
  • Locators in Selenium
  • Dynamic Xpath
  • Dynamic CSS
  • Handle drop-downs
  • How to work with file upload
  • Handle Alerts & Popups
  • Handle Multiple Windows
  • Mouse Hover event in Selenium
  • Right Click
  • Double Click
  • Drag and Drop
  • Capture Screenshots in Selenium
  • Parameterization
  • Synchronization
  • Implicit Wait, Explicit Wait and Fluent Wait in Selenium
  • Implicit Waits
  • Explicit WebDriver Waits
  • Fluent Wait In Selenium
  • Apache POI
  • How To Read Data From Excel File
  • How To Write Data In Excel File
  • Database Testing Using MSSQL
  • Database Testing Using MySQL
  • Database Testing Using DB2
  • Handle Ajax Call in Selenium
  • Listeners in Selenium
  • Handling JavaScript in Selenium
  • Stale Element Reference Exception in Selenium
  • Integrate Sikuli with Selenium
  • Headless Browser Testing 
  • Headless Browser Testing using HtmlUnitDriver
  • Headless Browser Testing using PhanthomJSDriver


  • TestNG Installation
  • TestNG Complete Tutorial


  • Extent Reports Introduction
  • Extent Reports Generation
  • Capturing Screenshots & Including In Extent Reports
  • Extent Reports Version 4


  • ANT Build Tool - How To Download & Install
  • Maven Build Tool - How To Download & Install
  • Creating Maven Selenium Project
  • GIT Integration with Selenium
  • Jenkins - How To Download & Install
  • Jenkins - Executing TestNG Scripts
  • Jenkins - Generating Reports After Test Execution
  • Jenkins - Executing Maven Project
  • Create build and Execute build for nightly execution
  • Send Email report based on build Status
  • Selenium Continuous Integration with Jenkins [Selenium – Maven – Git – Jenkins] – Step By Step Guide


  • Running Selenium Tests On BrowserStack
  • Kobiton - Mobile Testing Platform with Real Devices


  • Mobile Testing Platform with Real Devices


  • What is Framework & Types of Framework
  • Page Object Model Design Pattern
  • Data Driven Framework
  • How to explain Test Automation Framework or Selenium Automation Framework Architecture In Interview

  • API Testing:

  • Learn API Testing
  • Postman Tutorial (API Testing with Postman)


  • Test Automation Framework Interview Questions
  • Selenium Interview Questions
  • TestNG Interview Questions
  • Java Interview Questions
  • Python Interview Questions
  • API Testing Interview Questions


  • Automation Tester Resume
  • How To Run Failed Test Cases Using TestNG In Selenium WebDriver

    Run Failed Test Cases Using TestNG in Selenium WebDriver:

    At times, test cases may fail while running automated test scripts.  The reason may be anything (say, Network issue, System issue or browser issue) but as an automation tester, you need to execute the test scripts again. Here is a solution to run failed test cases using TestNG in Selenium.

    Don’t you want to take a screenshot on failure and attach that in your report?

    Yeah, as a tester we need to capture the failed steps. This post guides you on “How To Capture Screenshot and Insert it in Extent Reports

    We could execute the failed test cases in two ways.

    Case 1: Execute failed test cases using TestNG in Selenium – By using “testng-failed.xml”

    Steps To follow:

    1. After the first run of an automated test run. Right click on Project – Click on Refresh
    2. A folder will be generated named “test-output” folder. Inside “test-output” folder, you could find “testng-failed.xml”
    3. Run “testng-failed.xml” to execute the failed test cases again.

    Run Failed Test Cases Using TestNG

    Case 2: Execute failed test cases using TestNG in Selenium – By Implementing TestNG IRetryAnalyzer.

    Create a class to implement IRetryAnalyzer. Here I am creating a class (say, RetryFailedTestCases) and implementing IRetryAnalyzer.

    RetryFailedTestCases implements IRetryAnalyzer:

    Let’s create another class ‘RetryListenerClass’ by Implementing ‘IAnnotationTransaformer’ interface. transform method is called for every test during test run. A simple implementation of this ‘IAnnotationTransformer’ interface can help us set the ‘setRetryAnalyzer’ for ‘ITestAnnotation’. Add the above class name (RetryFailedTestCases.class) in the below program. This interface does its work in run time by adding annotation to the test methods.

    RetryListenerClass implements IAnnotationTransformer:

    Let us see the example by executing simple tests below. Here I took two test cases say Test1 and Test2.

    Testcase 1:

    Testcase 2:

    As per the lines of code in Test2, it will fail. So it (Test2) will be executed 2 times (we took the maxRetryCnt as 2) in Retry Class. First lets include below mentioned Listener to testng.xml file. Below mentioned syntax is to add Listener for RetryListnereClass

    Final testng.xml file should looks like below:

    Execute the testng.xml. Here is the output which I got. You could see in the below mentioned result that the Test 2 is executed three times as we have mentioned ‘maxRetryCnt = 2’. Even though we have just 2 tests, we could find total test runs are 4 in the result.

    This way we could run failed test cases using TestNG in Selenium.

    Complete TestNG Tutorial With Videos

    How To Run Failed Test Cases

    Get our latest blog posts delivered to your inbox

    Subscribe and get popular blog posts about software testing industry.


    1 thought on “How To Run Failed Test Cases Using TestNG In Selenium WebDriver”

    1. thanks very helpfull

    Leave a Comment

    Share via
    Copy link
    Powered by Social Snap