Reload chrome configuration(chrome capabilities during runtime)

My scripts can run on any machine (linux, windows, server machine). I want to validate the file was downloaded or not when I click on a link in my application. For this, I am creating a folder in my framework, whose location I am loading on runtime (because it is inside my framework).

I want to change the default download location of chrome for which I want ot set “download.default_directory” during execution before starting the chromedriver. I tried many approaches.

  1. assign the prefs during run time and start my own chromedriver. Later change the web driver in Driverfactory to the driver started by me.

Map<String, Object> prefs = new HashMap<String, Object>();
options.setExperimentalOption(“prefs”, prefs);

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);


It doesn’t set the user preference when the driver is started by WebUI.openBrowser ( checked in the logs)

  1. Overwrite “” file with the prefs before starting the WebUI.openBrowser(). (tried both- a. in the test case, b. in the test listener @beforeSuite).

However, it seems that the chrome settings are loaded when the test case is run and it cannot be changed.
The prefs are not set when the chromedriver is started by WebUI. However, if I run the test case again, prefs will be set because the prefs are set in the settings file.

I want to know, is there a way that I can reload the capabilities of chrome during the test case execution before launching the browser?

It is fixed now.
We need to open the URL using the custom chrome driver that we are using first and then change the DriverFactory to the our chrome driver. I was doing the opposite.

The last steps in 1 should be:
ChromeDriver driver = new ChromeDriver(capabilities);