Sha256: 84a5bc9a46bdf82980db46f00448fc50346b442d7954c768ec4389a33660a216

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

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

      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 configure
        initialize_options
        yield options if block_given? && options
      end

      # driver_path can be configured as a proc. Running this proc early allows
      # us to only update the webdriver once and avoid race conditions when
      # using parallel tests.
      def preload
        case type
        when :chrome
          ::Selenium::WebDriver::Chrome::Service.driver_path.try(:call)
        when :firefox
          ::Selenium::WebDriver::Firefox::Service.driver_path.try(:call)
        end
      end

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

        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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
actionpack-7.1.1 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.0 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.0.rc2 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.0.rc1 lib/action_dispatch/system_testing/browser.rb
actionpack-7.1.0.beta1 lib/action_dispatch/system_testing/browser.rb