Selenium-webdriver系列教程(17)————為firefox設定下載檔案的儲存目錄
阿新 • • 發佈:2019-01-31
Firefox為我們提供了非常豐富的配置功能,下面的程式碼就實現了配置下載目錄的功能。
Ruby程式碼
通過這段程式碼,在測試進行時,firefox會將pdf檔案下載到我們設定的目錄中去。
不過如下是屬性是不允許使用者進行配置的:
Ruby程式碼
Ruby程式碼
- profile = Selenium::WebDriver::Firefox::Profile.new
- profile['browser.download.dir'] = "/tmp/webdriver-downloads"
- profile['browser.download.folderList'] = 2
- profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
- driver = Selenium::WebDriver.for:firefox, :profile => profile
通過這段程式碼,在測試進行時,firefox會將pdf檔案下載到我們設定的目錄中去。
不過如下是屬性是不允許使用者進行配置的:
Ruby程式碼
- FROZEN_PREFERENCES = {
- "app.update.auto" => 'false',
- "app.update.enabled" => 'false',
- "browser.download.manager.showWhenStarting" => 'false',
- "browser.EULA.override"
- "browser.EULA.3.accepted" => 'true',
- "browser.link.open_external" => '2',
- "browser.link.open_newwindow" => '2',
- "browser.safebrowsing.enabled" => 'false',
- "browser.safebrowsing.malware.enabled"
- "browser.search.update" => 'false',
- "browser.sessionstore.resume_from_crash" => 'false',
- "browser.shell.checkDefaultBrowser" => 'false',
- "browser.tabs.warnOnClose" => 'false',
- "browser.tabs.warnOnOpen" => 'false',
- "devtools.errorconsole.enabled" => 'true',
- "dom.disable_open_during_load" => 'false',
- "extensions.logging.enabled" => 'true',
- "extensions.update.enabled" => 'false',
- "extensions.update.notifyUser" => 'false',
- "network.manage-offline-status" => 'false',
- "network.http.phishy-userpass-length" => '255',
- "network.http.max-connections-per-server" => '10',
- "prompts.tab_modal.enabled" => "false",
- "security.warn_entering_secure" => 'false',
- "security.warn_submit_insecure" => 'false',
- "security.warn_entering_secure.show_once" => 'false',
- "security.warn_entering_weak" => 'false',
- "security.warn_entering_weak.show_once" => 'false',
- "security.warn_leaving_secure" => 'false',
- "security.warn_leaving_secure.show_once" => 'false',
- "security.warn_submit_insecure" => 'false',
- "security.warn_viewing_mixed" => 'false',
- "security.warn_viewing_mixed.show_once" => 'false',
- "signon.rememberSignons" => 'false',
- "toolkit.networkmanager.disable" => 'true',
- "javascript.options.showInConsole" => 'true',
- "browser.dom.window.dump.enabled" => 'true',
- "dom.report_all_js_exceptions" => "true"
- }.freeze