Capturing screenshots of the browser via Selenium is fairly easy to achieve (see a sample method here), but triggering a screenshot only when a test fails is useful for both debugging and result reporting, however this requires a little more code and some modifications to your tests. JUnit5 For Junit5,…