1

我想在 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)

第二种变体不起作用,浏览器将文件下载到每台远程计算机上的默认下载位置

请帮我解决这个问题

4

1 回答 1

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
于 2012-05-23T21:06:02.803 回答