Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Selenium中更改Firefox默认下载设置_Ruby On Rails_Ruby_Firefox_Selenium - Fatal编程技术网

Ruby on rails 在Selenium中更改Firefox默认下载设置

Ruby on rails 在Selenium中更改Firefox默认下载设置,ruby-on-rails,ruby,firefox,selenium,Ruby On Rails,Ruby,Firefox,Selenium,我正在深入学习如何在Ruby中使用Cucumber和Selenium Webdriver。对它完全陌生 我有一个测试,我需要测试CSV文件下载是否正常。目前在Firefox中,出现了一个弹出窗口,Selenium无法集中精力,测试失败。我想在Selenium中更改Firefox的默认设置,以便下载将自动转到下载文件夹并完全跳过弹出框阶段 我看到了一些答案: profile = Selenium::WebDriver::Firefox::Profile.new profile["browser.d

我正在深入学习如何在Ruby中使用Cucumber和Selenium Webdriver。对它完全陌生

我有一个测试,我需要测试CSV文件下载是否正常。目前在Firefox中,出现了一个弹出窗口,Selenium无法集中精力,测试失败。我想在Selenium中更改Firefox的默认设置,以便下载将自动转到下载文件夹并完全跳过弹出框阶段

我看到了一些答案:

profile = Selenium::WebDriver::Firefox::Profile.new
profile["browser.download.folderList"] = 1 # use the custom folder defined in "browser.download.dir" below
profile["browser.download.dir"] = 'C:\Users\OSAT TESTING\Downloads'
profile["browser.helperApps.neverAsk.saveToDisk"] = 'application/csv'
然而,对于如何放置此代码,没有任何解释。测试步骤或env.rb文件等是否在代码中

救命啊,这真让我头疼

谢谢


尝试这种配置

我只在Capybara+Selenium+Firefox+PDF下载的环境中遇到过类似的问题。在这里找到了适合我的解决方案:

希望这能为你们中的一些人节省一些麻烦

Capybara.register_driver :selenium_autodownload do |app|
  Selenium::WebDriver::Firefox::Binary.path = ENV['CUSTOM_FF_PATH'] if ENV['CUSTOM_FF_PATH'].present?
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['browser.download.folderList'] = 2
  profile['browser.download.saveLinkAsFilenameTimeout'] = 1
  profile['browser.download.manager.showWhenStarting'] = false
  profile['browser.download.dir'] = "#{Rails.root}/spec/downloads/"
  profile['browser.download.downloadDir'] = "#{Rails.root}/spec/downloads/"
  profile['browser.download.defaultFolder'] = "#{Rails.root}/spec/downloads/"
  profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf,application/x-pdf,application/octet-stream"
  profile["pdfjs.disabled"] = true
  profile["plugin.scan.plid.all"] = false
  profile["plugin.scan.Acrobat"] = "99.0"
  Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
[编辑]请记住,如果此驱动程序用作默认驱动程序,并且您正在套件中测试pdf预览,则测试将失败,因为此驱动程序实例中禁用了预览

如果是这种情况,请注册另一个驱动程序并将其用作默认驱动程序

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
Capybara.default_driver = :selenium
并使用另一个驱动程序进行特定测试

it 'downloads the pdf file', :driver => :selenium_autodownload

当使用它时,我得到了以下错误:nil:NilClass(NoMethodError)的未定义方法'present'?如果不删除这一行,您是否在rails应用程序中使用它?Selenium::WebDriver::Firefox::Binary.path=ENV['CUSTOM\u FF\u path']如果ENV['CUSTOM\u FF\u path']]。present?”我必须通过删除profile.aspect行进行修改,并删除与rails的连接。下载的文件现在直接进入下载文件夹。你的帮助是无价的,谢谢你。我现在只需要指向cucumber查看我的下载文件夹。
it 'downloads the pdf file', :driver => :selenium_autodownload