How to change download path in the existing browser

I am trying create test cases for reports and need to sort and check downloaded reports, how to change download path in the existing browser?

I only found an option with the settings before starting the browser:

public class CustomChromeDriver {

public static void createChromeWebDriverCustomDownload(String downloadPath) {
	String projDir = RunConfiguration.getProjectDir()
		
		// add Chrome preferences
	HashMap<String, Object> chromePrefs = new HashMap<String, Object>()
	chromePrefs.put("download.default_directory", downloadPath)
	chromePrefs.put("download.prompt_for_download", false)
		
		// specify path to ChromeDriver
	System.setProperty("webdriver.chrome.driver", projDir + "\\Files\\chromedriver.exe")
	ChromeOptions options = new ChromeOptions()
	options.setExperimentalOption("prefs", chromePrefs)

		// create web driver
	WebDriver driver = new ChromeDriver(options)
	
		// use your driver instead of default one
	DriverFactory.changeWebDriver(driver)
	}
}

Let’s drag this guy out of bed… :sleeping:

@Brandon_Hein

Set the download.default_directory desired capability:

The Name will be ‘prefs’, the Type will be ‘String’, and the Value will be ‘download.default_directory=/path/to/folder’

This video might be helpful for you too:

If i understand this correctly, it will be before lauch and for all tests after.
Can i change download path after launch or always need to reopen browser?
example:

  1. set download path
  2. open browser
  3. download file
  4. change download path
  5. download another file in different folder

Right, this would be set for the lifetime of the Test Case/Test Suite. Otherwise you’ll have to create your own driver, pass it up to the factory class, etc. as you’ve done above.

1 Like