所以我需要在app.properties文件中设置文件夹路径名称值。我还想在当前时间戳之后命名它,这样当它用于创建文件时,它也会创建文件夹。我目前所做的不起作用。
screenshot.events = STARTED,SUCCEEDED,FAILED,STEP
screenshot.path = C:/Automation/${timestamp}
webdriver.type=CHROME
答案 0 :(得分:2)
这里有3个选项:
您可以在启动Spring Boot应用程序时定义所需的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}
@Value("${screenshot.path}")
public void setScreenshotPath(String screenshotPath) {
this.screenshotPath =
screenshotPath.replace("${timestamp}", System.currentTimeMillis());
}
@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());
答案 1 :(得分:0)
我会简化它。只需在application.properties中定义根路径:
screenshot.root.path = C:/Automation/
在保存Selenium屏幕截图时,以编程方式附加时间戳路径部分。