If your UI automation code takes screenshots of failure in the test method or page method, then it’s not good. We should handle that using a listener Or have a base class containing AfterMethod annotation that captures screenshots of failure.
Use a lateral approach (i.e. base class with afterMethod) if you aren’t using listeners in your framework.
Go through this well-explained article by Alex Siminiuc for more details: