Take ScreenShot in Selenium

Code to take screenshot


The "." sign will make sure that the screenshot is stored in current test run directory

Here Screenshot folder has been added to the test. And the screen shot will be saved here.


Main Code:

public void tcu() throws Exception{
            driver.manage().window().maximize();
            driver.get("https://mail.rediff.com/cgi-bin/login.cgi");
            TakesScreenshot ts = (TakesScreenshot)driver;
            File source = ts.getScreenshotAs(OutputType.FILE);
            FileHandler.copy(source, new File("./screenshot/na.jpg"));
            driver.close();
           
    }

No comments:

Post a Comment