环境: robotframework-selenium2library 2库
我正在selenium2library中寻找一种方法,通过在FirefoxProfile中设置首选项来自动下载文件,因为这是我可以找到的解决方案。但是,我似乎无法使用selenium2library中列出的方式将首选项配置文件导入selenium2library中的浏览器中。
使用selenium:
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)
我可以在open_browser()中找到selenium2library (),但是它只占用一个目录,而不是使用像selenium2library这样的首选项配置文件的灵活性。
Selenium2Library:
open_browser(self, url, browser='firefox', alias=None,remote_url=False, desired_capabilities=None,ff_profile_dir=None)
如果我能像robotframework-selenium2library?中的selenium那样做的话,能给我一些启示吗?
我在https://github.com/rtomac/robotframework-selenium2library/issues/18上发现了一个关于这个的封闭性问题
但是,它似乎使用配置文件目录,而不是灵活地设置firefox配置文件的首选项。
谢谢!!
发布于 2015-03-04 22:41:40
我可以在open_browser()中找到selenium2library,但它只吃一个目录
不是的。它还会吃偏好。长话短说是这样:
我不太清楚您如何实际使用robotframework-selenium2library。我要说的常见用法是运行导入selenium2library的robotframework测试用例(即简单的UTF-8文本文件)。您的问题的可能解决方案如下(不用说,所有变量都应该在*** 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}但是,您的问题表明您打算直接使用selenium2library提供的python函数(如您在问题中提到的selenium2library)。在这种情况下,您需要做的就是用参数desired_capabilities适当地调用该函数。
请注意关于该参数的文档(完整代码可以找到这里):
如果您为remote指定了一个值,您还可以指定' desired_capabilities‘,它是键1:val1,key2:val2中的一个字符串,将用于为远程服务器指定desired_capabilities。这对于为internet指定代理服务器或指定使用saucelabs.com的浏览器和os等操作非常有用。'desired_capabilities‘也可以是一个二叉树(创建字典创建),以允许更复杂的配置。
https://stackoverflow.com/questions/28553322
复制相似问题