Sha256: 33c2a24bc756053fe6b1c62d3f9ca18ce3fa60474bfb9d6426d3a3970ec28217

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module ActionDispatch
  module SystemTesting
    class Browser # :nodoc:
      attr_reader :name

      def initialize(name)
        @name = name
        set_default_options
      end

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

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

      def configure
        yield options if block_given?
      end

      # driver_path is lazily initialized by default. Eagerly set it to
      # avoid race conditions when using parallel tests.
      def preload
        case type
        when :chrome
          resolve_driver_path(::Selenium::WebDriver::Chrome)
        when :firefox
          resolve_driver_path(::Selenium::WebDriver::Firefox)
        end
      end

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

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

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

        def resolve_driver_path(namespace)
          namespace::Service.driver_path = ::Selenium::WebDriver::DriverFinder.path(options, namespace::Service)
        end
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.3.4/lib/action_dispatch/system_testing/browser.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actionpack-7.1.3.4/lib/action_dispatch/system_testing/browser.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actionpack-7.1.3.4/lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.3.4 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.3.2 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.3.1 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.3 lib/action_dispatch/system_testing/browser.rb