无法在Ruby + Webdriver中更改Remote Chrome的默认下载目录

时间:2012-05-23 12:34:33

标签: ruby google-chrome webdriver

我想在我的Webdriver + Ruby测试中使用Chrome来下载远程计算机上的文件。 在我的开发人员计算机上,使用此代码一切正常:

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = Settings::DEFAULT_DOWNLOAD_DIRECTORY
@@driver = Selenium::WebDriver.for :chrome, :profile => profile

但我想在几台远程计算机上使用运行代码并使用此代码

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = "/mnt/samba/share_location/"
caps = Selenium::WebDriver::Remote::Capabilities.chrome(:profile => profile)
@@driver = Selenium::WebDriver.for(:remote, :url => "http://" +remote_server + ":4444/wd/hub", :desired_capabilities => caps)

第二个变种没有工作,浏览器下载文件到每个远程计算机上的默认下载loaction

请帮我解决这个问题

1 个答案:

答案 0 :(得分:2)

是的,遗憾的是,这不是很直观。我会尝试为将来的版本改进它。这是现在的解决方法:

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = "/mnt/samba/share_location/"

data = profile.as_json

caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps['chromeOptions'] = {
  'profile'    => data['zip'],
  'extensions' => data['extensions']
}

driver = Selenium::WebDriver.for :remote, :desired_capabilities => caps