Back to All Scenarios
Scenario 75 of 100
Debugging
Intermediate
Troubleshooting and Debugging Failed TestNG Suites
π οΈScenario Overview
Troubleshooting and Debugging Failed TestNG Suites
Key Takeaways & Cheat Sheet
- βInspect detailed stack traces to identify assertion vs driver errors
- βUtilize ITestListener hooks to log failure parameters dynamically
- βReview XML suite configurations to verify parallel thread limits
- βAnalyze test output reports (emailable-report.html) for resource blocks
Short Direct Answer
To debug TestNG failures, inspect the stack trace to determine if the failure was a functional assertion bug (`AssertionError`) or an automation driver issue (`WebDriverException`). Use a custom listener class that implements `ITestListener` to capture screenshots and output system parameters on failures, and analyze the generated TestNG reports.
β οΈ Senior Warning (Red Flag)
Do not ignore stack traces by swallowing exceptions in generic try-catch blocks. Let exceptions propagate so TestNG can log the failure reasons and compile correct reports.
π‘ STAR Deep Dive Explanation & Pro Tip
Listeners are highly extensible. You can use them to automatically update test management platforms (like Jira or Quality Center) with failure logs and screenshots.
SeleniumAutomation.java
Selenium 4 + Javaimport org.testng.ITestListener;
import org.testng.ITestResult;
// β
Logging failure variables inside a custom TestNG Listener
public class FailureTracker implements ITestListener {
@Override
public void onTestFailure(ITestResult result) {
System.err.println("--- TEST FAILED: " + result.getName() + " ---");
System.err.println("Exception: " + result.getThrowable().getMessage());
// Log parameters if using DataProviders
Object[] params = result.getParameters();
if (params.length > 0) {
System.err.println("Failed with parameters: ");
for (Object param : params) {
System.err.println(" -> " + param.toString());
}
}
}
}