2016-05-23 87 views
3

我正在使用Cucumber和Ruby。當通過Selenium-Webdriver在Chrome中運行測試時,我想將下載位置更改爲測試文件夾,而不是用戶下載文件夾。下載位置Selenium-webdriver Cucumber Chrome

我現在的鍍鉻驅動程序設置像這樣:

Capybara.default_driver = :selenium 
Capybara.register_driver :selenium do |app| 
    Capybara::Selenium::Driver.new(app, :browser => :chrome, 
     desired_capabilities: { 
     'chromeOptions' => { 
     'args' => %w{ window-size=1920,1080 } 

    } 
    } 
    ) 
    end 

我需要什麼補充有改變下載位置嗎?

回答

7

下載目錄可以設置與download.default_directory偏好:

require 'capybara' 
require 'selenium-webdriver' 

Capybara.register_driver :chrome do |app| 
    Capybara::Selenium::Driver.new(app, 
    :browser => :chrome, 
    :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(
     'chromeOptions' => { 
     'args' => [ "--window-size=1920,1080" ], 
     'prefs' => { 
      'download.default_directory' => File.expand_path("C:\\Download"), 
      'download.prompt_for_download' => false, 
      'plugins.plugins_disabled' => ["Chrome PDF Viewer"] 
     } 
     } 
    ) 
) 
end 

session = Capybara::Session.new(:chrome) 
+0

你的先生,是一位紳士。謝謝。我一直在嘗試很多組合。我錯過了'File.expand_path' – Tom