繁体   English   中英

使用selenium2library设置自动下载首选项配置文件

[英]Set auto download preference profile using selenium2library

环境:robotframework-selenium2library

我正在selenium2library中寻找一种通过在FirefoxProfile中设置首选项来自动下载文件的方法,因为这是我可以找到的解决方案。 但是,似乎我无法使用在selenium webdriver中列出的方式将首选项配置文件导入selenium2library中的浏览器。

使用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)

我可以在selenium2library中找到open_browser(),但是它只吃一个目录,而不是像selenium webdriver这样使用首选项配置文件的灵活性。

Selenium2Library:
open_browser(self, url, browser='firefox', alias=None,remote_url=False, desired_capabilities=None,ff_profile_dir=None)

如果我可以像robotframework-selenium2library中的Selenium Webdriver一样进行操作,谁能给我一些启发?

我在Github上发现了一个关于此的封闭问题https://github.com/rtomac/robotframework-selenium2library/issues/18

但是,似乎使用配置文件目录而不是灵活地设置Firefox配置文件的首选项。

谢谢!!

我可以在selenium2library中找到open_browser(),但它只占用一个目录

不。它也有偏好。 长话是这样的:

我不太确定您实际上如何使用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函数(例如您在问题中提到的open_browser )。 在这种情况下,您需要做的就是使用适当设置的参数desired_capabilities来调用该函数。

请注意该参数的文档(完整的代码可在此处找到):

如果为remote指定一个值,则还可以指定'desired_capabilities',它是key1:val1,key2:val2格式的字符串,将用于为远程服务器指定desired_capabilities。 这对于执行诸如为Internet Explorer指定代理服务器或在使用saucelabs.com时指定浏览器和操作系统之类的操作很有用。 “ desired_capabilities”也可以是字典(使用“ Create Dictionary”创建),以允许进行更复杂的配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM