how to take a screenshot on windows 10 code example
Example 1: windows screenshot shortcut
Windows key + Shift + S
Example 2: take cropped screenshot windows
Windows key + Shift + S
Example 3: how to take a screenshot
---------- Screenshot on WINDOW ----------------
>> Windows + Shift + S
---------- Screenshot on MAC ----------------
>> Shift + Command + 4
Example 4: how to take screenshot in windows 7
1. Open Snipping Tool. Press Esc and then open the menu you would like to capture.
2. Pres Ctrl+Print Scrn.
3. Click on the arrow next to New and select Free-form, Rectangular, Window or Full-screen.
4. Take a snip of the menu.
Example 5: how to take screenshot in win 10
Win + Alt + PrtScn
Example 6: how to take a screenshot
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>"));
HOW TO TAKE SCREENSHOT FOR FAILED SCENARIOS
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
}
}
==========================================================================================