123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::SystemTesting::Browser

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name) ⇒ Browser

[ GitHub ]

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

def initialize(name)
  @name = name
  set_default_options
end

Instance Attribute Details

#name (readonly)

[ GitHub ]

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

attr_reader :name

Instance Method Details

#configure {|options| ... }

Yields:

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 36

def configure
  yield options if block_given?
end

#options

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 26

def options
  @options ||=
    case type
    when :chrome
      ::Selenium::WebDriver::Chrome::Options.new
    when :firefox
      ::Selenium::WebDriver::Firefox::Options.new
    end
end

#preload

driver_path is lazily initialized by default. Eagerly set it to avoid race conditions when using parallel tests.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 42

def preload
  case type
  when :chrome
    resolve_driver_path(::Selenium::WebDriver::Chrome)
  when :firefox
    resolve_driver_path(::Selenium::WebDriver::Firefox)
  end
end

#resolve_driver_path(namespace) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 74

def resolve_driver_path(namespace)
  # The path method has been deprecated in 4.20.0
  if Gem::Version.new(::Selenium::WebDriver::VERSION) >= Gem::Version.new("4.20.0")
    namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.new(options, namespace::Service.new).driver_path
  else
    namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.path(options, namespace::Service)
  end
end

#set_default_options (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 52

def set_default_options
  case name
  when :headless_chrome
    set_headless_chrome_browser_options
  when :headless_firefox
    set_headless_firefox_browser_options
  end
end

#set_headless_chrome_browser_options (private)

[ GitHub ]

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

def set_headless_chrome_browser_options
  configure do |capabilities|
    capabilities.add_argument("--headless")
    capabilities.add_argument("--disable-gpu") if Gem.win_platform?
  end
end

#set_headless_firefox_browser_options (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 68

def set_headless_firefox_browser_options
  configure do |capabilities|
    capabilities.add_argument("-headless")
  end
end

#type

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/system_testing/browser.rb', line 15

def type
  case name
  when :headless_chrome
    :chrome
  when :headless_firefox
    :firefox
  else
    name
  end
end