File download to specific directory

Hi all, I’m trying to set chrome browser working in incognito mode to save all downloadable files in a specific directory inside of my framework, but it’s not working.
So when Download button is clicked in incognito mode than Windows Save As dialogue box opens and making an attempt to save a file on my Desktop’s Download folder. Could someone please let me know what could be wrong here.

*** Settings ***
Library SeleniumLibrary 75 5 run_on_failure=Nothing

Library …/…/common_utilities/resources/common_keywords.py

Variables …/locators/common_locators.py

*** Variables ***
${downloadDir} functional_tests/web_app/management/resources/Downloads

*** Keywords ***
Configure Chrome
${chromeOptions} = Evaluate
sys.modules[‘selenium.webdriver’].ChromeOptions() sys, selenium.webdriver
${prefs} = Create Dictionary download.default_directory=${downloadDir}
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
${options}= Evaluate selenium.webdriver.ChromeOptions()
Call Method ${options} add_argument --incognito
Call Method ${options} add_argument --disable-notifications
Call Method ${options} add_argument --headless
Create Webdriver Chrome chrome_options=${options}
Set Window Size 1920 1080

Hi,

I use this syntax that works well.

*** Variables ***
    ${downloadDir} functional_tests/web_app/management/resources/Downloads

*** Tests Cases ***
     VAR    &{browser_prefs}    download.default_directory=${downloadDir}    plugins.always_open_pdf_externally=${True}
     ${chrome_options}    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
     Call Method    ${chrome_options}    add_experimental_option    prefs    ${browser_prefs}
     Open Browser    ${url}    chrome    options=${chrome_options}

Usually I set the ${downloadDir} as EMPTY, and fill/construct the path in the test setup to have a folder for each suite/test.

Regards
Charlie

Thank you for response Charlie,
when I set up to:

${DOWNLOAD_DIR} ${CURDIR}
it works and it downloads files to my local directory.

But when I updated it to:

${downloadDir} functional_tests/web_app/management/resources/Downloads
It starts saving files to my Desktop Dowload folder like if this folder functional_tests/web_app/management/resources/Downloads doesn’t exist, but it does, I’m confused what’s wrong with this path…

Hi,

Is the folder you want to target in the projext/execution directory?
Maybe the path is misinterpreted, it seems it doesn’t have nothing prior “functional_tests”

You could try to provide a relative of full path, or even something like this:

${EXECDIR} /functional_tests/web_app/management/resources/Downloads

Also depending of the OS check the slashes/backslash es or use ${/} for multiplatform.

Regards
Charlie

1 Like