2017-01-11 27 views
0

路徑值,因此我需要設置在app.properties文件的文件夾路徑名值。我也想在當前的時間戳來命名它,這樣,當它被用來創建一個文件時,它還會創建該文件夾。我現在已經不工作。添加時間戳變量到文件夾中的應用程序屬性

screenshot.events = STARTED,SUCCEEDED,FAILED,STEP 
screenshot.path = C:/Automation/${timestamp} 
webdriver.type=CHROME 

回答

0

我不知道如果時間戳是每執行一個一次性的東西,或者如果你需要它是動態的,在一次執行過程創建多個文件夾。這裏有3個選項:

1.啓動

推出的春季啓動應用程序時,您可以創建所需SystemProperty:

public static void main(String[] args) { 
     System.setProperty("timestamp",String.valueOf(System.currentTimeMillis())); 

     new SpringApplicationBuilder() // 
       .sources(Launcher.class)// 
       .run(args); 
    } 

然後,你application.properties現在的樣子,你定義它的工作:

screenshot.path = C:/Automation/${timestamp} 

2.注射

@Value("${screenshot.path}") 
public void setScreenshotPath(String screenshotPath) { 
    this.screenshotPath = 
     screenshotPath.replace("${timestamp}", System.currentTimeMillis()); 
} 

3.使用中 - 執行期間的多個時間戳

@Value("${screenshot.path}") 
private String screenshotPath; 
... 
new File(screenshotPath.replace("${timestamp}", System.currentTimeMillis()); 

//or the following without the need for ${timestamp} in screenshot.path 
//new File(screenshotPath + System.currentTimeMillis()); 
0

我會簡化它。就在application.properties只定義根路徑:

screenshot.root.path = C:/Automation/ 

,並以編程添加時間戳路徑的一部分,當你節省硒截圖。

相關問題