Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download location Selenium-webdriver Cucumber Chrome

I'm using Cucumber with Ruby. When running tests in Chrome via Selenium-Webdriver, I'd like to alter the download location to the test folder instead of the users download folder.

My current chrome driver is set up like so:

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

What would I need to add there to change the download location please?

like image 506
Tom Avatar asked May 23 '16 13:05

Tom


People also ask

Where is ChromeDriver saved?

Chromium/Google Chrome Note : For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. You can also override the Chrome binary location following Using a Chrome executable in a non-standard location .


1 Answers

The download directory can be set with the download.default_directory preference:

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)
like image 96
Florent B. Avatar answered Oct 06 '22 05:10

Florent B.