I generally take screenshots in the @After
hook which gets called after every cucumber scenario. @After
hook method takes a special Scenario
object so that you can embed your screenshots in your reports. Here is an example on how to take screenshots in the event your scenario fails,
@After
public void tearDown(Scenario scenario) {
try {
if (scenario.isFailed()) {
final byte[] screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
} finally {
driver.quit();
}
}