If your UI automation code takes screenshot on failure in 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 on failure. Use 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: https://levelup.gitconnected.com/the-good-the-bad-and-the-ugly-of-taking-screenshots-with-selenium-and-java-c9da23e09842
A blog about my testing stories where I pen down my thoughts about test automation covering primarily Selenium, Java, Rest Assured, Karate, Maven, TestNG, Postman, newman, Jenkins, Git, Azure DevOps, etc.