GeckoDriver
概觀
GeckoDriver 是一個獨立應用程式,用於與基於 Gecko 的瀏覽器(例如 Firefox)互動。 它以 Rust 撰寫,並由 Mozilla 維護。
從 Firefox 48 開始,GeckoDriver 是自動化 Firefox 的唯一方法,過去屬於 Selenium 一部分的傳統 FirefoxDriver 已不再支援。 在內部,它會將 HTTP 呼叫轉換為 Marionette,這是 Mozilla 內建於 Firefox 的自動化協定。
下載
可以從 GitHub 上的發行頁面下載 GeckoDriver。 發行說明也在此處提供。 或者,您可以使用 geckodriver NPM 套件作為專案中的相依性
npm install geckodriver --save-dev
建議 Selenium 2.x 使用者使用 v0.9 版本,而 Selenium 3 使用者應使用最新版本。
獨立使用
Nightwatch 可以自動管理 GeckoDriver 服務,就像其他 WebDriver 服務(例如 ChromeDriver)一樣。 若要直接使用 GeckoDriver,請將此新增至您的 nightwatch.json
{
"webdriver": {
"start_process" : true,
"server_path": "./bin/geckodriver-0.23",
"cli_args": [
"--log", "debug"
],
"port": 4444
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName" : "firefox",
"acceptInsecureCerts": true
}
}
}
}
與 Selenium 伺服器搭配使用
如果您透過 Selenium Server 使用 GeckoDriver,只需將 cli 引數 "webdriver.gecko.driver"
設定為指向二進位檔案的位置。 例如:
{
"selenium" : {
"start_process" : true,
"server_path" : "./bin/selenium-server-standalone-3.{VERSION}.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.gecko.driver" : "./bin/geckodriver"
}
}
}
GeckoDriver 也可以作為獨立應用程式使用。 使用步驟記錄在 GitHub 上:https://github.com/mozilla/geckodriver#usage。
命令列使用
$ ./bin/geckodriver-0.23 -help
geckodriver 0.23.0
USAGE:
geckodriver-0.23 [FLAGS] [OPTIONS]
FLAGS:
--connect-existing Connect to an existing Firefox instance
-h, --help Prints help information
--no-e10s Start Firefox without multiprocess support (e10s) enabled
-V, --version Prints version information
-v Set the level of verbosity. Pass once for debug level logging and twice for trace level logging
OPTIONS:
-b, --binary <BINARY> Path to the Firefox binary, if no binary capability provided
--log <LEVEL> Set Gecko log level [values: fatal, error, warn, info, config, debug, trace]
--marionette-port <PORT> Port to use to connect to gecko (default: random free port)
--host <HOST> Host ip to use for WebDriver server (default: 127.0.0.1)
-p, --port <PORT> Port to use for WebDriver server (default: 4444)
Firefox 功能
GeckoDriver 支援名為 firefoxOptions
的功能,它採用 Firefox 特定的偏好設定值。 詳細資訊可在 GeckoDriver GitHub 頁面上取得:https://github.com/mozilla/geckodriver#firefox-capabilities。
Firefox 設定檔
可以透過在 firefoxOptions
字典中設定 profile
屬性來指定 Firefox 設定檔,如上所述。 這可以是設定檔目錄的 base64 編碼 zip,可用於安裝擴充功能或自訂憑證。
實作狀態
GeckoDriver 尚未完全完成功能,這表示它尚未完全符合 WebDriver 標準或與 Selenium 完全相容。 實作狀態可以在 Marionette MDN 頁面上追蹤。