A robust framework captures diagnostic evidence on failure automatically — a screenshot, page source, and logs — via listeners/hooks, and handles exceptions so failures are clear and the suite continues cleanly.
Rather than each test capturing its own screenshot, a listener (TestNG ITestListener.onTestFailure / JUnit TestWatcher.testFailed / Cucumber @After) grabs a screenshot (TakesScreenshot), attaches it to the report, and logs the error context — automatically for every failing test. The framework should also ensure teardown always runs (quit the driver in @After/finally) even when a test throws, and translate low-level exceptions into meaningful messages. Retry (sparingly) can be centralized too. Automatic failure evidence dramatically cuts debugging time and is a hallmark of a mature framework.
onTestFailure(result) takes a screenshot, saves page source, logs the error, and embeds them in ExtentReports — so a nightly failure is diagnosable from the report alone without re-running locally.
How do you ensure every failing test automatically produces a screenshot without adding code to each test?