How to save the temporary screenshots into the permanent folder?

Taking screenshots is very important while running test execution. Especially, while running automation test cases using selenium, we need to know which test case is passing and failing.  Screenshots is the proof to pass the test cases and to check why the test case is failed.

Below code is written to capture the screenshot and it will save it to the created permanent folder on your local drive.

I have created folder naming Selenium_Screenshots to save my screenshots.

Code:
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Point;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class TakeScreenshotAnotherFolder {
 
public static void main(String args[]) throws IOException
{

//Launching firefox browser
WebDriver driver = new FirefoxDriver();
  
//Launching website
driver.get("http://www.techyvicky.com/");
  
//Screenshot syntax and code
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
   
//Copying screenshot and placing it to the folder.
FileUtils.copyFile(scrFile, new File("c:\\Selenium_Screenshots\\screenshot.png"));

} 
}
Socialize It and Share the post with your friends
SOCIALIZE IT →
FOLLOW US →
SHARE IT →