How to take screenshot in selenium?
Using below function (getScreenShot) you can get screenshot.
MyMethods.java
import java.io.File;
import java.io.IOException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.io.FileHandler;
public class ScreenShot {
public static String getScreenShot(String imageName, WebDriver driver) {
TakesScreenshot ts = (TakesScreenshot)driver;
File scrFile = ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+"/src/main/resources/unicodeTech/screenshots/"+imageName+System.currentTimeMillis()+".png";
//System.out.println(path);
File destination =new File(path);
try {
FileHandler.copy(scrFile,destination);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return path;
}
}
Call above method in your program by writing this:
MyMethods.getScreenShot("WelcomePageAfterLogin (Image name) ", driver);
Comments
Post a Comment