Created
October 23, 2015 23:57
-
-
Save prawinch/9d96974a6570d2ddae08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import javax.imageio.ImageIO; | |
import java.awt.*; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
public class FullScreenShot { | |
final static String fileLocation = "D:\\ScreenShot\\"; | |
public static void main(String[] args) { | |
try { | |
WebDriver driver = new FirefoxDriver(); | |
driver.get("http://www.testautomation4all.com"); | |
driver.findElement(By.id("some-non-existing-element")).click(); | |
} catch (Exception e) { | |
captureEnirePageScreenshot("Unexpected error"); | |
} | |
} | |
public static void captureEnirePageScreenshot(String screenShotName) { | |
try { | |
// Capture the dimensions of the screen | |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); | |
// Convert the dimensions into rectangle object type | |
Rectangle rec = new Rectangle(d); | |
// Take the screenshot using the Robot instance | |
Robot robot = new Robot(); | |
BufferedImage myImage = robot.createScreenCapture(rec); | |
File img = new File(fileLocation + screenShotName + ".png"); | |
ImageIO.write(myImage, "png", img); | |
System.out.println("Done"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment