[英]Set auto download preference profile using selenium2library
Environment: robotframework-selenium2library 环境: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. 我正在selenium2library中寻找一种通过在FirefoxProfile中设置首选项来自动下载文件的方法,因为这是我可以找到的解决方案。 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.
但是,似乎我无法使用在selenium webdriver中列出的方式将首选项配置文件导入selenium2library中的浏览器。
Using selenium webdriver: 使用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")
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(),但是它只吃一个目录,而不是像selenium webdriver这样使用首选项配置文件的灵活性。
Selenium2Library: 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? 如果我可以像robotframework-selenium2library中的Selenium Webdriver一样进行操作,谁能给我一些启发?
I found one closed issue talking about this on Github https://github.com/rtomac/robotframework-selenium2library/issues/18 我在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. 但是,似乎使用配置文件目录而不是灵活地设置Firefox配置文件的首选项。
Thank you!! 谢谢!!
I can find the open_browser() in selenium2library but it only eats a directory
我可以在selenium2library中找到open_browser(),但它只占用一个目录
No. It also eats preferences. 不。它也有偏好。 The long story goes like this:
长话是这样的:
I am not quite sure how you actually use robotframework-selenium2library. 我不太确定您实际上如何使用robotframework-selenium2library。 The common usage, I would say, is to run robotframework test cases (ie simple UTF-8 text files) which import selenium2library.
我会说, 通常的用法是运行导入selenium2library的robotframework测试用例(即简单的UTF-8文本文件)。 A possible solution to your problem would look like this (it goes without saying that all variables should be defined below
*** Variables ***
): 可能的解决方案如下所示(不用说,所有变量都应在
*** 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. 但是,您的问题表明您打算直接使用selenium2library提供的python函数(例如您在问题中提到的
open_browser
)。 In that case, all you need to do is to call that function with parameter desired_capabilities
set appropriately. 在这种情况下,您需要做的就是使用适当设置的参数
desired_capabilities
来调用该函数。
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.
如果为remote指定一个值,则还可以指定'desired_capabilities',它是key1:val1,key2:val2格式的字符串,将用于为远程服务器指定desired_capabilities。 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.
这对于执行诸如为Internet Explorer指定代理服务器或在使用saucelabs.com时指定浏览器和操作系统之类的操作很有用。 'desired_capabilities' can also be a dictonary (created with 'Create Dictionary') to allow for more complex configurations.
“ desired_capabilities”也可以是字典(使用“ Create Dictionary”创建),以允许进行更复杂的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.