Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 16, 2016

Executing Only Failed Tests in TestNG





Executing only failed tests in TestNG will discuss about how we can execute only failed test cases in the test suite once the execution of the suite completed. Most of the times when we execute bulk tests as suite then there is a chance of failing some of the tests.

For these failures there may be so many reasons. Will see some of them below:

1.Some of the elements may not load properly.
2.Due to some network slowness.
3.Functionality may got changed.
4.Locator value may got changed.. Etc…

Because of the reasons tests will fail. After completion of the execution if there are any failures, immediately we can not raise bugs. In the above scenarios failures due to 1,2 and 4 will not cause the bugs as this is because of loading elements and network slowness. But due to 3, we can raise the bugs.

But how we can come to know that the failures because of which reason. To get the confirmation we need to rerun the failed scripts to know the exact reason. Then how we can execute only failed tests?

To execute only failed tests we have provision in the TestNg. After completion of the suite execution; just refresh the project folder then you can find a folder called “test-output” and there you can find an xml file called “testng-failed.xml”. This xml file contains only failed test cases. So, we can execute this xml file to rerun the failed test again.

Below is the sample program:

import org.testng.Assert;
import org.testng.annotations.Test;

public class OnlyFailedTestExecution {
    @Test
    public void testOne() {
        Assert.assertTrue(true);
        System.out.println("Pass Test Case");
    }

    @Test
    public void testTwo() {
        Assert.assertTrue(false);
        System.out.println("Faile Test Case");
    }
}

Execute the above program using below testng.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="OnlyFailedTestExecution"/>
    </classes>
  </test>
</suite>

Once your execute the above xml file then we can find the below output:

1

Now we want to execute only failed tests. For this we will go to the test-output folder and will execute the testng-failed.xml. Then we can see the below output.

2

3

In the above output we can see that only failed test got executed. And it ignores the execution of passed tests.
This way we can execute the only failed tests in testNg.
Please watch You tube video for better understanding.



Share this post: on Twitter on Facebook

Capture Screenshot for Failed Tests in TestNG Running TestNG Tests Programmatically

Related Posts

Excel to DataProvider

TestNG

Read data from Excel to DataProvider in Selenium

Running TestNG programmatically

TestNG

Running TestNG Tests Programmatically

Capture Screenshot for Failed Tests

TestNG

Capture Screenshot for Failed Tests in TestNG

Preserve Order in TestNG

TestNG

Preserve Order in TestNG

PRIORITIZING TESTS

TestNG

Prioritizing Tests in TestNg

EXECUTE MULTIPLE XML FILES

TestNG

Execute Multiple XML files in TestNG

CUSTOM REPORTER IN TESTNG (1)

TestNG

Custom Reporter in TestNG

CUSTOM LOGGER IN TESTNG

TestNG

Custom Logger in TestNG

ASSERTIONS

TestNG

TestNG Assertions

PARALLEL EXECUTION OF classes

TestNG

Parallel Execution of Classes In TestNG

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025