Sha256: 749330316fbf32c139c4714b0105ce2c222547469ff03e3262c5ba15e85e1784

Contents?: true

Size: 1.95 KB

Versions: 70

Compression:

Stored size: 1.95 KB

Contents

def add_emulate_device(browser_options, emulate_device)
  if emulate_device == 'notebook'
    browser_options.add_emulation(device_metrics: { width: 800, height: 400, pixelRatio: 1, touch: true })
  else
    browser_options.add_emulation(device_name: emulate_device)
  end

  browser_options
end

def default_options(headless:)
  options = Selenium::WebDriver::Chrome::Options.new
  options.args << '--disable-site-isolation-trials'
  # options.args << '--start-maximized'

  if headless
    options.args << '--headless'
    options.args << '--disable-gpu' if Gem.win_platform?
  end

  options
end

def chrome_driver_gen(headless: true, emulate_device: nil, debugger: false)
  lambda do |app|
    Capybara::Selenium::Driver.load_selenium
    browser_options = default_options(headless:)

    if debugger
      port = ENV.fetch('CHROME_PORT') { '9014' }
      browser_options.debugger_address = "127.0.0.1:#{port}"
    end

    browser_options = add_emulate_device(browser_options, emulate_device) if emulate_device

    Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
  end
end

Capybara.register_driver :selenium_chrome, &chrome_driver_gen(headless: false)
Capybara.register_driver :selenium_chrome_notebook, &chrome_driver_gen(headless: false, emulate_device: 'notebook')
Capybara.register_driver :selenium_chrome_iphone, &chrome_driver_gen(headless: false, emulate_device: 'iPhone 6')
Capybara.register_driver :selenium_chrome_headless, &chrome_driver_gen(headless: true)
Capybara.register_driver :selenium_chrome_headless_notebook,
                         &chrome_driver_gen(headless: true, emulate_device: 'notebook')
Capybara.register_driver :selenium_chrome_headless_iphone,
                         &chrome_driver_gen(headless: true, emulate_device: 'iPhone 6')
Capybara.register_driver :selenium_chrome_debugger, &chrome_driver_gen(headless: false, debugger: true)

Capybara.javascript_driver = ENV.fetch('WEBDRIVER') { 'selenium_chrome_notebook' }.to_sym

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
pg_rails-7.0.8.pre.alpha.86 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.56 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.55 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.54 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.53 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.52 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.51 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.50 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.49 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.48 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.47 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.46 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.45 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.44 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.43 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.42 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.41 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.40 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.39 pg_rails/lib/pg_rails/capybara_support.rb
pg_rails-7.0.8.pre.alpha.38 pg_rails/lib/pg_rails/capybara_support.rb