Sha256: 59b3cd377c6e7911a9a96db8bc3342d187d15ccc0cfd29b63ade380b61038bb4

Contents?: true

Size: 1.88 KB

Versions: 21

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

module ActionDispatch
  module SystemTesting
    class Driver # :nodoc:
      def initialize(name, **options, &capabilities)
        @name = name
        @browser = Browser.new(options[:using])
        @screen_size = options[:screen_size]
        @options = options[:options]
        @capabilities = capabilities

        @browser.preload
      end

      def use
        register if registerable?

        setup
      end

      private
        def registerable?
          [:selenium, :poltergeist, :webkit].include?(@name)
        end

        def register
          define_browser_capabilities(@browser.capabilities)

          Capybara.register_driver @name do |app|
            case @name
            when :selenium then register_selenium(app)
            when :poltergeist then register_poltergeist(app)
            when :webkit then register_webkit(app)
            end
          end
        end

        def define_browser_capabilities(capabilities)
          @capabilities.call(capabilities) if @capabilities
        end

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

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

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

        def register_webkit(app)
          Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash.merge(@options)).tap do |driver|
            driver.resize_window_to(driver.current_window_handle, *@screen_size)
          end
        end

        def setup
          Capybara.current_driver = @name
        end
    end
  end
end

Version data entries

21 entries across 19 versions & 5 rubygems

Version Path
actionpack-6.0.2.2 lib/action_dispatch/system_testing/driver.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/system_testing/driver.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.2.1 lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.2 lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.2.rc2 lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-6.0.1/lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.2.rc1 lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-6.0.1/lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.1 lib/action_dispatch/system_testing/driver.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.1.rc1 lib/action_dispatch/system_testing/driver.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb
actionpack-6.0.0 lib/action_dispatch/system_testing/driver.rb