Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
How to take screen shot in WebDriver?

Solved 1 Answers 77 Views Test Automation
0 1
I am using Selenium WebDriver to automate chrome, I am required to take the screen shot of my browser while the test is running. So how do we take screen shot in Selenium WebDriver?

-- I am using Java.

1 Answer

0
Best answer
0
public String takeScreenShot(){
String filename = null;
    try{
        long id = Thread.currentThread().getId();
        BufferedImage imagename = new Robot().createScreenCapture(new Rectangle(
            Toolkit.getDefaultToolkit().getScreenSize()));
    filename = "./target/surefire-reports/"+ id + "/screenshot.jpg"
        ImageIO.write(imagename, "jpg", new File(filename));
    }
    catch( Exception e ) {
        e.printStackTrace();
    }
    return filename;
}
answered by
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...