Hi all,
For those who are asking what I did, There are basically 3 methods i created to simplify things.
#1 createDownloadFolder()
#2 getCurrentBrowser()
#3 changeDownloadPath(string path, string browser)
If you need only the changeDownloadPath, here is my code simple code snippet. We are only using chrome and firefox so my code is only for chrome and firefox. You can just basically add another elseif for other browsers.
@Keyword
def changeDownloadPath(String browser, String path){
if(browser=="chrome" || browser=="chrome-headless"){
HashMap<String, Object> chromePrefs = new HashMap<String, Object>()
chromePrefs.put("download.default_directory", path)
chromePrefs.put("download.directory_upgrade", true)
chromePrefs.put("browser.set_download_behavior", 'allow')
chromePrefs.put("download.prompt_for_download", false)
RunConfiguration.setWebDriverPreferencesProperty("prefs", chromePrefs)
} else if(browser=="firefox" || browser=="firefox-headless"){
HashMap<String, Object> profile = new HashMap<String, Object>()
profile.put("browser.download.dir", path)
profile.put("browser.download.folderList", 2)
profile.put("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/msword, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.ms-excel, application/vnd.ms-excel, application/pdf")
profile.put("browser.download.manager.showWhenStarting",false);
profile.put("pdfjs.disabled", true);
RunConfiguration.setWebDriverPreferencesProperty("firefox_profile", profile)
} else{
KeywordUtil.logInfo("-- CHANGE DOWNLOAD PATH FAILED --")
}
}
Hope this helps. 