I just want to ask if it is possible to change the download directory by passing a variable instead of a fixed download path during runtime? (e.g. C:\users\user\Downloads)
I tried passing it through settings but unfortunately there is no variable Type and I am guessing you can only put a fixed path there.
The reason behind is I want to create a temporary folder everytime i run the test is because I have a lot of files to be downloaded and I want to separate them per category and delete them after execution.
So far i tried RunConfiguration.setWebDriverPreferenceproperty like this:
Unfortunately, itâs not working. I am thinking that I should pass âprefsâ on the first parameter but not sure what to pass on the second as it should be a dictionary Type.
Though I was finally able to make it work by passing HashMap instead of the contents.
now I was finally able to use this custom method to make the download path âdynamicâ by passing a variable instead of setting it up hardcoded under settings.
Hi porte.marvin, I have to do same, can you please share how you have done this.
As of now I am hardcoding downloadpath but it will get changed on other machine, eg username.
How can i get tha downloadpath on real time and then perform actions using that path.
Thanks, but I need more validations, it works only for chrome , I have to do for other browsers aswell. So i am trying like below âŚbut not that opens two browsers, one with OpenBrowser and another with ChromeDriver initializing- please help
def pageload(String browser) {
WebUI.openBrowser('')
WebDriver driver = DriverFactory.getWebDriver()
WebUI.closeBrowser()
println("Driver new is "+ driver)
long startTime = System.currentTimeMillis()
println("The Value of brwonser is : "+ browser);
String downloadPath = RunConfiguration.getProjectDir()+ '/' +'download_Upload/'
println("The Chrome_Browser Download path is : " +downloadPath)
Map<String, Object> browserPrefs = new HashMap<String, Object>()
browserPrefs.put('download.default_directory', downloadPath)
browserPrefs.put('download.directory_upgrade', true)
browserPrefs.put('download.prompt_for_download', false)
if(String.valueOf(driver).contains('chrome')) {
println("Chrome found")
System.setProperty('webdriver.chrome.driver', DriverFactory.getChromeDriverPath())
println("declaring ChromeOptions")
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption('prefs', browserPrefs)
println("calling change web driver")
driver=new ChromeDriver(options)
DriverFactory.changeWebDriver(driver)
println("executed change web driver")
}
else {
DriverFactory.changeWebDriver(driver)
}
println("Rest of the program")
long endTime = System.currentTimeMillis()
long totalTime = endTime - startTime
long TimeInSeconds = totalTime / 1000
def String page_load_time = ("Time to load page " +TimeInSeconds + " in Seconds")
println (page_load_time)
WebUI.navigateToUrl(GlobalVariable.url_app_navigator)
println("Navigate to site")
WebUI.maximizeWindow()
WebUI.delay(10)
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.
Itâs not working for me.
Iâm getting below error message.
Reason:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;