0

Is there a way to set the path for download that will work for different systems? I'm running tests manually and my download path is C:\Users\myUser\Download.

For my colleague the middle folder will be different. Tests runs with Bamboo on Linux server and path there is different.

Is there a way to set one path that will work everywhere, or a way to check the actual download path and look there?

Can I remove files after download? I can't manipulate with driver, or chrome options - blocked by framework in company.

PiTu
  • 13
  • 2

2 Answers2

1

This is the path for the system "Downloads" folder:

public String downloadPath = System.getProperty("user.home") + "\\Downloads\\";

Here is to remove the files after download:

public boolean isFileDownloaded(String fileName) {
    File dir = new File(downloadPath);
    File[] dirContents = dir.listFiles();

    for (int i = 0; i < dirContents.length; i++) {
        if (dirContents[i].getName().equals(fileName)) {
            dirContents[i].delete();
            return true;
        }
    }
    return false;
}
Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36
carlosng07
  • 28
  • 9
0

The below link should provide you the answer you need :) how to change file download location in Webdriver while using chrome driver/firefox driver

Summary: In essence you need to add it as a preference in your ChromeOptions

String downloadFilepath = "/path/to/download/directory/";
Map<String, Object> preferences = new Hashtable<String, Object>();
preferences.put("profile.default_content_settings.popups", 0);
preferences.put("download.prompt_for_download", "false");
preferences.put("download.default_directory", downloadFilepath);

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
xX13ENXx
  • 1
  • 3