Environment: robotframework-selenium2library
I am looking for a way in selenium2library to make the auto-downloading the file by setting the preference in FirefoxProfile as this is the solution I can find. However, it seems that I can not use the way I listed as following in selenium webdriver to import the preference profile into the browser in selenium2library.
Using selenium 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",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
browser = webdriver.Firefox(firefox_profile=fp)
I can find the open_browser() in selenium2library but it only eats a directory instead of the flexibility of using the preference profile like selenium webdriver.
Selenium2Library:
open_browser(self, url, browser='firefox', alias=None,remote_url=False, desired_capabilities=None,ff_profile_dir=None)
Could anyone shed me some light on this if I can do the same way as selenium webdriver in robotframework-selenium2library?
I found one closed issue talking about this on Github https://github.com/rtomac/robotframework-selenium2library/issues/18
However, it seems to use profile directory instead of having the flexibility to set the preference for firefox profile.
Thank you!!
I can find the open_browser() in selenium2library but it only eats a directory
No. It also eats preferences. The long story goes like this:
I am not quite sure how you actually use robotframework-selenium2library. The common usage, I would say, is to run robotframework test cases (ie simple UTF-8 text files) which import selenium2library. A possible solution to your problem would look like this (it goes without saying that all variables should be defined below *** Variables ***
):
*** Settings ***
Library Selenium2Library
Library Collections
*** Variables ***
*** Test Cases ***
MyTestCase
${preferences} = Create Dictionary browser.download.folderList 2 browser.download.manager.showWhenStarting False # and so on ....
Open Browser <yourURL> desired_capabilities=${preferences}
However, your question suggests that you intend to directly use python functions (like open_browser
that you mentioned in your question) provided by selenium2library. In that case, all you need to do is to call that function with parameter desired_capabilities
set appropriately.
Please note the documentation on that parameter ( full code is to be found here ):
If you specify a value for remote you can also specify 'desired_capabilities' which is a string in the form key1:val1,key2:val2 that will be used to specify desired_capabilities to the remote server. This is useful for doing things like specify a proxy server for internet explorer or for specify browser and os if your using saucelabs.com. 'desired_capabilities' can also be a dictonary (created with 'Create Dictionary') to allow for more complex configurations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.