-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTakeScreenshot1.java
More file actions
34 lines (22 loc) · 1.03 KB
/
TakeScreenshot1.java
File metadata and controls
34 lines (22 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package selenium;
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;
import org.testng.ITestResult;
public class TakeScreenshot1 {
WebDriver driver;
public void captureScreenshot(ITestResult result) throws Exception {
if (ITestResult.FAILURE == result.getStatus()) {
// Create Reference of TakeScreenshot Interface and Type Casting
TakesScreenshot ts = (TakesScreenshot) driver; // Type Casting of the Interface
// Call getScreenshotAs() method to capture the screenshot in terms of FILE
// getScreenshotAs() method return type is FILE
File source = ts.getScreenshotAs(OutputType.FILE);
// Copy File to specific location here /sceenshot/ is folder result is file name .png is extention
FileUtils.copyFile(source, new File("./Screenshots/" + result.getName() + ".png"));
System.out.println(result.getName() + " method() Screenshot Captured");
}
}
}