我想在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)
第二个变体不起作用,浏览器下载文件到每台远程计算机上的默认下载位置
请帮我解决这个问题
是的,不幸的是这不是很直观。我将尝试为将来的版本改进它。以下是目前的解决方法:
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