2013-04-08 5 views
0
나는 두 가지 방법을 만드는 오전

에 저장됩니다 :다음은 현재 날짜와 시간

public static String currentDateTime() { 
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 
    Calendar cal = Calendar.getInstance(); 
    String cal1 = dateFormat.format(cal.getTime()); 
    return cal1; 
} 
public static void screenShot(WebDriver driver) throws IOException { 
    File scrnsht = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
    String datetime = GenericFunctions.currentDateTime(); 
    FileUtils.copyFile(scrnsht, new File("D:\\Screenshot1.png"+datetime)); 
} 

그러나, 나는 다음 내 WebDriver 스크립트에서 폴더를 테이크 스크린 샷 방법을 사용할 때 만들었습니다. 현재 날짜와 시간으로 스크린 샷을 찍고 싶습니다. 제게 잘못 생각한 부분을 알려주십시오.

답변

1

에서 "CAL1"와 "날짜"를 대체합니다

FileUtils.copyFile(scrnsht, new File("D:\\Screenshot1.png"+datetime)); 

또는

을 시도해보십시오이

Calendar calendar = Calendar.getInstance(); 
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss"); 
String destFileName = screenShotPath.getAbsoluteFile()+File.separator+"failure_screenshots_"+formater.format(calendar.getTime())+".png"; 
+0

같은 존재한다면 대신 1을 사용하면 당신은 루프를 사용하거나 할 수 있습니다 것이 좋습니다 수의 쓸모없는 코드이므로 제거하고 싶을 수도 있습니다. – aimbire

+1

파일이 png가되지 않습니까? 나는 "D : \\ Screenshot1-"+ datetime + ".png"'가 더 적절하다고 제안 할 것이다. – Nashibukasan

+0

아니요. 나에게 적합하지 않습니다. 새 코드를 제공하면 "스크린 샷을 찍을 때 현재 날짜와 시간을 절약 할 것입니다." – user2181837

0
public static void screenShot(WebDriver driver) throws IOException { 
File scrnsht = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
String datetime = GenericFunctions.currentDateTime(); 
FileUtils.copyFile(scrnsht, new File("D:\\Screenshot1.png"+datetime)); 

}

파일이 Screenshot1처럼 보였다됩니다

.png 만, datetime은 아닙니다. 어디서나 추가되었습니다. 대신 당신이 FileUtils.copyFile(scrnsht, new File("D:\\Screenshot1"+datetime+".png"));

또한 경우 1 함수가 이미로, 턴 문자열 날짜를 대신 2를 추가하거나 또한 그