Selenium을 사용하여 Print screen 버튼을 시뮬레이션할 수 있습니다. 스크린샷은 화면 인쇄 버튼으로 캡처됩니다. 스크린샷 캡처는 3단계 프로세스입니다. 이는 실패 분석을 위한 중요한 단계입니다.
드라이버 개체를 TakeScreenshot으로 변환합니다. 인터페이스.
구문
TakesScreenshot s = (TakesScreenshot)driver;
그런 다음 getScreenshotAs를 사용하여 방법은 이미지 파일을 가지고 FileUtils.copyFile이 있는 위치에 해당 파일을 복사합니다. 방법.
구문
File sp=s.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(sp, new File("path of image file")); 예
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.apache.commons.io.FileUtils;
import java.io.File;
public class PrintScreenSimulate {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.tutorialspoint.com/index.htm");
// screenshot capturing
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("logopage.png"));
driver.quit();
}
}