我将 Robot Framework 与 Selenium2Library 一起用于自动化前端测试。通常我在 Firefox 浏览器中运行这些测试。自 Firefox 版本 47 以来,Selenium2Library 的内置 FirefoxDriver 不再工作。通过互联网搜索了一下,发现我必须切换到 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
我再次尝试在 Internet 上找到一种方法来设置 GeckoDriver 可执行文件的路径,但我只找到了一种用于 Java 的方法。既不适用于 Python,也不适用于 Robot Framework。有人知道如何在 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
