Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
204 views
in Test Automation by
recategorized by
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 like 0 dislike
by
selected by
 
Best answer
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;
}


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...