python - 如何使用Robot Framework设置系统属性 "webdriver.gecko.driver"?

标签 python selenium-webdriver robotframework

我将 Robot Framework 与 Selenium2Library 一起使用来进行自动化前端测试。通常我在 Firefox 浏览器中运行这些测试。从 Firefox 47 版本开始,Selenium2Library 的内置 FirefoxDriver 不再工作。 A 在互联网上搜索了一下,发现我必须切换到 Marionette aka。壁虎驱动程序。

尝试此操作时,我收到以下错误消息:

Suite setup failed: WebDriverException: Message: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/jgraham/wires. The latest version can be downloaded from https://github.com/jgraham/wires

我再次尝试在互联网上寻找一种设置GeckoDriver可执行文件路径的方法,但我只找到了一种适用于Java的方法。既不适用于 Python,也不适用于机器人框架。有人知道如何在 Python 或 Robot Framework 中设置系统属性吗?

最佳答案

如果您不想使用 Marionette,请按照 Mukesh 的回答并更改版本。 如果您想使用 Marionette,最简单的方法是将线(或将来的 geckodriver)添加到系统路径,如建议 by the Mozilla developers .

Python 绑定(bind)不支持设置 GeckoDriver 的路径,除非通过 Webdriver __init__ 的参数。因此,如果无法修改系统路径,唯一的方法是将可执行文件的路径传递到 Selenium 中。在 Robot Framework 中,您可以使用 Create Webdriver 来执行此操作。 Firefox 的 __init__ 记录在 here .

*** Settings ***
Library           Selenium2Library
Library           Collections

*** Test Cases ***
Specifying Path To GeckoDriver
    ${ff default caps}    Evaluate    sys.modules['selenium.webdriver'].common.desired_capabilities.DesiredCapabilities.FIREFOX    sys,selenium.webdriver
    Set To Dictionary    ${ff default caps}    marionette=${True}
    Create Webdriver    Firefox    executable_path=C:\\stuff\\wires.exe
    Go To    https://stackoverflow.com
    Sleep    2 s
    [Teardown]    Close All Browsers

关于python - 如何使用Robot Framework设置系统属性 "webdriver.gecko.driver"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38307054/

相关文章:

testing - 由于源字符串,无法比较机器人测试中的字符串

python - 如何序列化 beautifulsoup 访问路径?

python - 如何将年龄分箱特征替换为数值数据?

python - 用户 :pass proxies with selenium

python - 如何为 "doubleclick"和 "find icon and type <some text>"的 Robot Framework 编写 Python 自定义库?

python - 数据驱动型测试之间的测试设置

python - 将数据输入 SQLite

python - 如何解析带标志和不带标志的命令行参数

c# - 在 Selenium 中启用扩展启动 firefox

c# - 如何使用 C# 处理 selenium 中的 Ad On