Capturing Screenshots

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

protected void takeScreenshot(String fileName) {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir") + "//test-output//screenshots//" + fileName + ".png";
try {
FileUtils.copyFile(scrFile, new File(path));
} catch (IOException e) {
e.printStackTrace();
}
}

Note: need apache commons io dependency

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

猜你喜欢

转载自www.cnblogs.com/amy2012/p/11624777.html