How to take screen shot in WebDriver?

Solved 1 Answers 75 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

Best answer
public String takeScreenShot(){
String filename = null;
        long id = Thread.currentThread().getId();
        BufferedImage imagename = new Robot().createScreenCapture(new Rectangle(
    filename = "./target/surefire-reports/"+ id + "/screenshot.jpg"
        ImageIO.write(imagename, "jpg", new File(filename));
    catch( Exception e ) {
    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.

We have resolved 1.2k+ Software Testing queries!

Top Contributors