how to take a screenshot
Press the Windows key + Shift + S. The screen will dim and the mouse pointer will change. You can drag to select a portion of the screen to capture. The screenshot will be copied to the clipboard, which you can paste into another program. (This shortcut only works if you have the latest version of Windows 10 installed, called the Windows 10 Creators Update.)
I have a tearDown method in my Hooks Class. I keep my screenshot codes in it.
It takes screenshot as soon as any scenario fails.
@After
public void tearDown(Scenario scenario) {
if(scenario.isFailed()) {
TakesScreenshot screen=(TakesScreenshot)Driver.getDriver();
final byte[] screenshot = screen.getScreenshotAs(OutputType.BYTES); ==>
taking screenshot
scenario.embed(screenshot, "image/png"); ==> adding screenshot to
the report
}
}
HOW TO TAKE SCREENSHOT IN ANY TEST CASE WITHOUT FAILURE
TakesScreenshot screen=(TakesScreenshot)Driver.getDriver();
File screenshot=screen.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("<your folder path here>"));