power_settings_new

How to take screen shot in WebDriver?

by
asked
0 like 0 dislike
80 views
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.

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.

1 Answer

answered by
selected by
0 like 0 dislike
 
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;
}

Related questions

add
...