I use WebDriverManager.chromedriver().setup();
for getting chrome property in my selenium tests. It works fine. I am trying to download a file by changing the default download location of chrome browser because I want to download the file to my java project classpath, rather than to my local machine, but I am unsure if WebDriverManager has such an implementation. Currently, I am trying something like this:
WebDriverManager.chromedriver().setup();
String downloadDir = System.getProperty("user.dir");
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("download.default_directory", downloadDir);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);
The code block works and downloads the file to the project classpath, as expected, but I think there would be a cleaner and shorter way to do it. I have done some research on the Bonigarcia WebDriverManager
dependency and some of its implementations but can't find anything helpful. Is there a better way to achieve the above?