123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::SystemTesting::Driver

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionpack/lib/action_dispatch/system_testing/driver.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(driver_type, **options, &capabilities) ⇒ Driver

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 10

def initialize(driver_type, **options, &capabilities)
  @driver_type = driver_type
  @screen_size = options[:screen_size]
  @options = options[:options] || {}
  @name = @options.delete(:name) || driver_type
  @capabilities = capabilities

  if driver_type == :selenium
    gem "selenium-webdriver", ">= 4.0.0"
    require "selenium/webdriver"
    @browser = Browser.new(options[:using])
    @browser.preload unless @options[:browser] == :remote
  else
    @browser = nil
  end
end

Instance Attribute Details

#name (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 8

attr_reader :name

#registerable?Boolean (readonly, private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 34

def registerable?
  [:selenium, :cuprite, :rack_test, :playwright].include?(@driver_type)
end

Instance Method Details

#browser_options (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 51

def browser_options
  @options.merge(options: @browser.options).compact
end

#register (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 38

def register
  @browser&.configure(&@capabilities)

  Capybara.register_driver name do |app|
    case @driver_type
    when :selenium then register_selenium(app)
    when :cuprite then register_cuprite(app)
    when :rack_test then register_rack_test(app)
    when :playwright then register_playwright(app)
    end
  end
end

#register_cuprite(app) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 61

def register_cuprite(app)
  Capybara::Cuprite::Driver.new(app, @options.merge(window_size: @screen_size))
end

#register_playwright(app) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 69

def register_playwright(app)
  screen = { width: @screen_size[0], height: @screen_size[1] } if @screen_size
  options = {
    screen: screen,
    viewport: screen,
    **@options
  }.compact

  Capybara::Playwright::Driver.new(app, **options)
end

#register_rack_test(app) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 65

def register_rack_test(app)
  Capybara::RackTest::Driver.new(app, respect_data_method: true, **@options)
end

#register_selenium(app) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 55

def register_selenium(app)
  Capybara::Selenium::Driver.new(app, browser: @browser.type, **browser_options).tap do |driver|
    driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
  end
end

#setup (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 80

def setup
  Capybara.current_driver = name
end

#use

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/driver.rb', line 27

def use
  register if registerable?

  setup
end