aboutsummaryrefslogtreecommitdiffstats
path: root/actionsystemtest/lib/action_system_test/driver_adapters.rb
blob: aead9d6f6054eb2944a62618cd1c3d0b5a8526c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module ActionSystemTest
  # == System Testing Driver Adapters
  #
  # By default Rails supports Capybara with the Selenium Driver. Rails provides
  # configuration setup for using the selenium driver with Capybara.
  # Additionally Rails can be used as a layer between Capybara and its other
  # supported drivers: +:rack_test+, +:selenium+, +:webkit+, or +:poltergeist+.
  #
  # *{RackTest}[https://github.com/jnicklas/capybara#racktest]
  # *{Selenium}[http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-2-aka-selenium-webdriver]
  # *{Webkit}[https://github.com/thoughtbot/capybara-webkit]
  # *{Poltergeist}[https://github.com/teampoltergeist/poltergeist]
  #
  # === Driver Features
  #
  # |                 | Default Browser       | Supports Screenshots? |
  # |-----------------|-----------------------|-----------------------|
  # | Rails' Selenium | Chrome                | Yes                   |
  # | Rack Test       | No JS Support         | No                    |
  # | Selenium        | Firefox               | Yes                   |
  # | WebKit          | Headless w/ Qt        | Yes                   |
  # | Poltergeist     | Headless w/ PhantomJS | Yes                   |
  module DriverAdapters
    extend ActiveSupport::Autoload

    autoload :CapybaraDriver
    autoload :RailsSeleniumDriver

    class << self
      # Returns driver for specified name.
      #
      #   ActionSystemTest::DriverAdapters.lookup(:rails_selenium_driver)
      #   # => ActionSystemTest::DriverAdapters::RailsSeleniumDriver
      def lookup(driver)
        if CapybaraDriver::CAPYBARA_DEFAULTS.include?(driver)
          CapybaraDriver.new(name: driver)
        elsif driver.is_a?(Symbol)
          klass = const_get(driver.to_s.camelize)
          klass.new
        else
          driver
        end
      end
    end
  end
end