JUnit
Selenium 테스트를
실행할 때 브라우저 세션의 화면 캡처를 작성하여 오류 조건을
표시할 수 있습니다. 나중에 보도록 테스트 케이스 또는 테스트 스위트
실행 결과에 이 화면 캡처를 포함할 수 있습니다.
이 태스크 정보
JUnit
Selenium 어댑터는 테스트를 실행할 때
JUnit
Selenium 테스트를 실행하는
JVM에 "selenium.screenshot.dir"이라는 Java™
시스템 특성을 설정합니다.
이 Java 시스템 특성 값은
어댑터를 실행하는 시스템에 있는 디렉토리의
전체 경로입니다. 실행된 각
JUnit
Selenium 테스트를 종료할 때
"selenium.screenshot.dir"로 지정된 디렉토리에서
이미지 파일(.png, .jpg, .jpeg, .gif, .tif, .bmp)을 찾습니다. 파일이 있으면
Quality Management 서버에 파일이 첨부되며 첨부된
해당 파일의 참조가 실행 결과에
포함됩니다.
예
다음 샘플 JUnit 코드는 브라우저의
현재 상태를 화면 캡처하여 "selenium.screenshot.dir"이 지정한 디렉토리에
화면 캡처 파일을 두는 방법을 표시합니다.
@Test
public void testWikipediaJUnit4_test1() throws Exception {
driver.get(baseURL + "/");
driver.findElement(By.id("searchInput")).clear();
driver.findElement(By.id("searchInput")).sendKeys("blueberries");
takeScreenShot("blueberry2.png"); // Capture screenshot of current state
driver.findElement(By.name("go")).click();
driver.findElement(By.cssSelector("p > i > a[title=\"Vaccinium\"]")).click();
takeScreenShot("vaccinium2.png"); // Capture screenshot of current state
driver.findElement(By.linkText("huckleberry")).click();
takeScreenShot("huckleberry2.png"); // Capture screenshot of current state
}
private void takeScreenShot(String fname) throws Exception {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String imageFileDir = System.getProperty("selenium.screenshot.dir");
if (imageFileDir == null)
imageFileDir = System.getProperty("java.io.tmpdir");
FileUtils.copyFile(scrFile, new File(imageFileDir, fname));
}