download.default_directory is working on windows but not working on Linux

1,981 views
Skip to first unread message

Vijay Shinde

unread,
May 2, 2021, 11:44:51 AM5/2/21
to ChromeDriver Users
Hi Team,

Need help for "download.default_directory" is working on windows but not working on Linux 

Issue Background:
I am using Selenium, Java and chrome to automate the website. It has one test case wherein it automatically downloads one file. I have tried below code on windows, it worked fine but when try to execute it through Jenkins job which is having Linux operating system, it has failed to download the file in given path.

ChromeOptions options = new ChromeOptions();

HashMap<String, Object> prefs = new HashMap<String, Object>();

prefs.put("download.prompt_for_download", false);
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1 );

String downloadFilepath = System.getProperty("user.dir") + "\\src\\test\\resources\\downloads";
if (System.getProperty("user.dir").startsWith("/home")) {
downloadFilepath = downloadFilepath.replace("\\", "/");
}
prefs.put("download.default_directory", downloadFilepath);

options.setExperimentalOption("prefs", prefs);

options.addArguments("start-maximized");
options.addArguments("--safebrowsing-disable-download-protection");
options.addArguments("safebrowsing-disable-extension-blacklist");
options.addArguments("--test-type");
options.addArguments("--disable-extentions");
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

WebDriver driver = new ChromeDriver(options);


The expectation is to download the file in the given path on Linux machine. But it is not downloading.

Could you please help to resolve this issue?


Thanks & Regrads,
Vijay Shinde

Ashwin Sathyanarayanan

unread,
May 3, 2021, 9:02:20 AM5/3/21
to ChromeDriver Users
I am also facing same issues. When i run in jenkins, it downloads the file to default project directory. When I point it to run in Openshift environment, it downloads in /home/selUser/downloads. 

Is this the expected behaviour?

Vijay Shinde

unread,
May 3, 2021, 10:25:50 AM5/3/21
to ChromeDriver Users
Hi Ashwin,

Thanks for your response.

If it is downloading in the default download directory on Linux server (as you mentioned /home/selUser/downloads) , then it is expected. 
Could you please let me know if "selUser" is the logged in user?
What changes you have done in the source code? could you able to share the script/changes?

If it is so, then it will be resolving one part of the problem.
Secondly, have you tried getting the file downloaded in our customized given folder path? as mentioned in my previous email as below,
String downloadFilepath = System.getProperty("user.dir") + "\\src\\test\\resources\\downloads";

Thanks & Regards,
Vijay Shinde

Ashwin Sathyanarayanan

unread,
May 5, 2021, 2:14:09 AM5/5/21
to ChromeDriver Users
Hi Vijay

In windows we give the custom path , and the file is getting downloaded to the location given(Eg. C:\Downloads - File gets downloaded in the specific location). 

In case of linux, when test execute inside the Jenkins, file gets downloaded to the root folder of where the project is present, it overrides the custom path provided in the Chrome options.

For openshift, default download directory is /home/seluser/Downloads, so file gets downloaded there. In this case also, it overrides the custom path provided in the Chrome options.

Insted of framing the path in code, I have given the full path directly.

Thanks 
Ashwin
Reply all
Reply to author
Forward
0 new messages