0

So I need to set a folder path name value in the app.properties file. I also want to name it after the current timestamp so that when it's used to create a file it'll also create the folder. What I current have doesn't work.

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

2 Answers2

6

Here's 3 options:

1. At startup

You can define the required SystemProperty when launching your Spring Boot Application:

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

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

Then, define your property in application.properties just the way you did:

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

2. At Injection

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

3. At usage - dynamic timestamps at execution

@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());
alexbt
  • 16,415
  • 6
  • 78
  • 87
1

I would simplify it. Just define only root path in application.properties:

screenshot.root.path = C:/Automation/

And append timestamp path part programmatically when you are saving Selenium screenshot.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92