【问题标题】:Set auto download preference profile using selenium2library使用 selenium2library 设置自动下载偏好配置文件
【发布时间】:2015-04-17 15:59:10
【问题描述】:

环境:robotframework-selenium2library

我正在 selenium2library 中寻找一种方法,通过在 FirefoxProfile 中设置首选项来自动下载文件,因为这是我能找到的解决方案。 但是,似乎我无法使用我在 selenium webdriver 中列出的方式将首选项配置文件导入 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)

我可以在 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 配置文件的首选项。

谢谢!!

【问题讨论】:

  • 非常感谢您提供任何建议。谢谢。

标签: python selenium selenium-webdriver robotframework


【解决方案1】:

我可以在 selenium2library 中找到 open_browser() 但它只吃 目录

没有。它也吃偏好。长篇大论是这样的:

我不太确定您实际上是如何使用 robotframework-selenium2library。我想说,common 的用法是运行导入 selenium2library 的机器人框架测试用例(即简单的 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

请注意有关该参数的文档( 完整代码见here):

如果您为远程指定一个值,您还可以指定 'desired_capabilities' 形式为字符串 key1:val1,key2:val2 将用于指定 desired_capabilities 到远程服务器。这对于做一些事情很有用,比如指定一个 Internet Explorer 或指定浏览器和操作系统的代理服务器 你使用 saucelabs.com。 'desired_capabilities' 也可以是 字典(使用“创建字典”创建)以允许更复杂的 配置。

【讨论】:

  • 感谢您提供更多信息。我直接使用库而不是编写食谱。我从 github 得到反馈,知道他们不支持将配置文件实例传递给 open_browser() 但您可以使用 recipe 来执行此操作似乎很有趣。
猜你喜欢
  • 2016-07-18
  • 2017-11-08
  • 2013-03-15
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 2013-03-27
  • 1970-01-01
相关资源
最近更新 更多