这个Selenium客户端绑定将尝试定位geckodriver来自系统的可执行文件PATH..您需要将包含可执行文件的目录添加到系统路径。在……上面Unix如果使用的是bash兼容的shell,则可以执行以下操作将其附加到系统的搜索路径中:export PATH=$PATH:/path/to/geckodriver
在……上面窗您需要更新PATH系统变量以将完整的目录路径添加到可执行文件中。原理与Unix相同。
下面所有使用任何编程语言绑定启动最新Firefox的配置都适用于Selenium2显式启用Marionette。使用Selenium3.0及更高版本,您不需要做任何事情来使用Marionette,因为默认情况下它是启用的。
要在测试中使用Marionette,您需要更新所需的功能来使用它。
爪哇 :
例外情况是,您需要下载最新的geckodriver.exe从…这里并下载geckodriver.exe作为带有变量的系统属性存在于计算机中的路径webdriver.gecko.driver在启动木偶驱动程序和启动Firefox之前,如下所示://if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly
through codeSystem.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");//Now you can Initialize marionette driver to launch fi
refoxDesiredCapabilities capabilities = DesiredCapabilities.firefox();capabilities.setCapability("marionette", true);WebDriver driver = new
MarionetteDriver(capabilities);
而为了Selenium3用作:-WebDriver driver = new FirefoxDriver();
.net :var driver = new FirefoxDriver(new FirefoxOptions());
Python :from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilitiescaps = DesiredCapabilities.FIREFOX# Tell the Python binding
s to use Marionette.# This will not be necessary in the future,# when Selenium will auto-detect what remote end# it is talking to.caps["mari
onette"] = True# Path to Firefox DevEdition or Nightly.# Firefox 47 (stable) is currently not supported,# and may give you a suboptimal ex
perience.## On Mac OS you must point to the binary executable# inside the application package, such as# /Applications/FirefoxNightly.app/Con
tents/MacOS/firefox-bin
caps["binary"] = "/usr/bin/firefox"driver = webdriver.Firefox(capabilities=caps)
红宝石 :# Selenium 3 uses Marionette by default when firefox is specified# Set Marionette in Selenium 2 by directly passing marionette: true# You mig
ht need to specify an alternate path for the desired version of FirefoxSelenium::WebDriver::Firefox::Binary.path = "/path/to/firefox"driver
= Selenium::WebDriver.for :firefox, marionette: true
JavaScript(Node.js) :const webdriver = require('selenium-webdriver');const Capabilities = require('selenium-webdriver/lib/capabilities').Capabilities;var capabil
ities = Capabilities.firefox();// Tell the Node.js bindings to use Marionette.// This will not be necessary in the future,// when Selenium
will auto-detect what remote end// it is talking to.capabilities.set('marionette', true);var driver = new webdriver.Builder().withCapabi
lities(capabilities).build();
使用RemoteWebDriver
如果你想用RemoteWebDriver在任何语言中,这将允许您使用Marionette在……里面Selenium网格。
Python:caps = DesiredCapabilities.FIREFOX# Tell the Python bindings to use Marionette.# This will not be necessary in the future,# when Selenium
will auto-detect what remote end# it is talking to.caps["marionette"] = Truedriver = webdriver.Firefox(capabilities=caps)
红宝石 :# Selenium 3 uses Marionette by default when firefox is specified# Set Marionette in Selenium 2 by using the Capabilities class# You might
need to specify an alternate path for the desired version of Firefoxcaps = Selenium::WebDriver::Remote::Capabilities.firefox marionette:
true, firefox_binary: "/path/to/firefox"driver = Selenium::WebDriver.for :remote, desired_capabilities: caps
爪哇 :DesiredCapabilities capabilities = DesiredCapabilities.firefox();// Tell the Java bindings to use Marionette.// This will not be necessary
in the future,// when Selenium will auto-detect what remote end// it is talking to.capabilities.setCapability("marionette", true);WebDriver
driver = new RemoteWebDriver(capabilities);
.netDesiredCapabilities capabilities = DesiredCapabilities.Firefox();// Tell the .NET bindings to use Marionette.// This will not be necessary
in the future,// when Selenium will auto-detect what remote end// it is talking to.capabilities.SetCapability("marionette", true);var driver
= new RemoteWebDriver(capabilities);
注意:就像其他浏览器供应商Selenium可以使用的其他驱动程序一样,Mozilla现在发布了一个可执行文件,它将与浏览器一起运行。跟随这,这个更多细节。