Unable to lauch browser instance when setting the capabilities for download directory in application.properties file

128 Views Asked by At

I'm using application properties file to set the capabilities of the chrome drive. Below is the code for that initially it worked fine but when I added "download.default_directory": "${dir.downloads}" it's not loading the driver as well.

dir.currentdirectory= ${expr:java.lang.System.getProperty("user.dir")}
dir.screenshots = ${dir.currentdirectory}\\resources\\screenshots
dir.downloads = ${dir.currentdirectory}\\resources\\downloads 
chrome.additional.capabilities={"browserName":"chrome","goog:chromeOptions": {"args": ["start-maximized", "--disable-popup-blocking", "disable-infobars", "--disable-extensions"], "extensions": [], "prefs": {"download.directory_upgrade": "true", "download.default_directory": "${dir.downloads}", "download.prompt_for_download": "false", "safebrowsing.enabled": "true"}}}

I tried access that value using below code to check the string and its showing correct value. Not sure why its not loading.

String myString = getBundle().getString("chrome.additional.capabilities");
System.out.println("=============="+myString);
1

There are 1 best solutions below

2
user861594 On

Following works fine for me:


dir.currentdirectory= ${expr:java.lang.System.getProperty("user.dir")}
dir.screenshots = ${dir.currentdirectory}/resources/screenshots
dir.downloads = ${dir.currentdirectory}/resources/downloads 
chrome.additional.capabilities={"browserName":"chrome","goog:chromeOptions": {"args": ["start-maximized", "--disable-popup-blocking", "disable-infobars", "--disable-extensions"], "extensions": [], "prefs": {"download.directory_upgrade": true, "download.default_directory": "${dir.downloads}", "download.prompt_for_download": false, "safebrowsing.enabled": true}}}

If you want to use \\ add addition \ for each \ because \ is escape char in properties file. For instance for a\b you need to set a\\b and for a\\b you need to set a\\\\b. Considering this you can also try as below:

dir.screenshots = ${dir.currentdirectory}\\\\resources\\\\screenshots.

As a side not you can use any system properties directly with configuration manager (so as parameter) and system properties has highest prority. So you don't need to use expr for to access system property. You can directly refer it as parameter. For example:

dir.screenshots = ${user.dir}/resources/screenshots
dir.downloads = ${user.dir}/resources/downloads