Home > Enterprise >  Firefox preference update is not applied with robot framework
Firefox preference update is not applied with robot framework

Time:02-18

I am trying to turn of Firefox download dialog. I used this piece of python code that use selenium library. This should make that file is directly download into entered path without additional asking.

from selenium import webdriver

def disable_download_dialog(path):
    fp = webdriver.FirefoxProfile()
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.manager.showWhenStarting", False)
    fp.set_preference("browser.download.dir", path)
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")
    fp.update_preferences()
    return fp.path 

Then I call this function in my RF test like this:

${ff_profile_path}=   disable download dialog    ${EXECDIR}\\path\\to\\my\\folder

and then Open browser like this:

Open Browser    ${url}    ${browser}    ff_profile_dir=${ff_profile_path}

From the test run I can see that download window is still displayed. The path to my folder, where I want to send downloaded file is displayed in test logs like this:

D:\\path\\to\\the\\folder\\named\\Downloads

And the firefox profile is really updated and saved in Temp file. But it looks like it's not loaded and therefore used for my test. The path to the firefox profile is like this:

C:\Users\surname~1.name\AppData\Local\Temp\tmp83d29mnz

ofc it's everytime a new profile created, what is not an issue. Maybe it could be great if I can also set the path for this firefox profile I created with python function.

So the question(s) here are:

Why the download dialog is still show when I disabled it?

Can be firefox profile saved in the folder that is defined by me?

CodePudding user response:

Ok, so I found out, what was the missing piece.

I added these two lines of code into the python function

fp.set_preference("browser.helperApps.alwaysAsk.force", False)
fp.set_preference("pdfjs.disabled", True)

So the final version of the function looks like this:

def disable_download_dialog(path):
    from selenium import webdriver
    fp = webdriver.FirefoxProfile()
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.manager.showWhenStarting", False)
    fp.set_preference("browser.download.dir", path)
    fp.set_preference("browser.helperApps.alwaysAsk.force", False)
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk",'application/pdf')
    fp.set_preference("pdfjs.disabled", True)
    fp.update_preferences()
    return fp.path
  • Related