/* | |
* | |
* | |
* Documentation: | |
* To take Screenshot anywhere in framework just use: | |
* utility.Screenshot.captureScreenshot(driver); | |
* Screenshot will be saved in directory: C:/selenium | |
* | |
* | |
*/ | |
package utility; | |
import java.io.File; | |
import org.apache.commons.io.FileUtils; | |
import org.openqa.selenium.OutputType; | |
import org.openqa.selenium.TakesScreenshot; | |
import org.openqa.selenium.WebDriver; | |
public class Screenshot { | |
public static void captureScreenshot(WebDriver driver) | |
{ | |
TakesScreenshot ts = (TakesScreenshot)driver; | |
File source = ts.getScreenshotAs(OutputType.FILE); | |
try { | |
FileUtils.copyFile(source, new File("C:/selenium/"+System.currentTimeMillis()+".png")); | |
System.out.println("Screenshot Taken"); | |
Log.info("Screenshot Taken"); | |
} | |
catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
System.out.println("Error while taking Screenshot"); | |
} | |
} | |
} |
How to take Screenshots in Selenium using Webdriver?
Reviewed by Ishan Dev Shukl
on
March 20, 2018
Rating:

Hats off to your presence of mind..I really enjoyed reading your blog. I really appreciate your information which you shared with us.
ReplyDeletesoftware testing training in chennai