1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch/system_testing/driver.rb
Fumiaki MATSUSHIMA ec99107a29 Pass options to driven_by
Capybara drivers can handle some options such like `url`.

### before

```
# test/test_helper.rb
Capybara.register_driver :remote_chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome, url: "http://example.com/wd/hub")
end

# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :remote_chrome
end
```

### after

```
# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"}
end
```
2017-03-13 19:59:01 +09:00

34 lines
813 B
Ruby

module ActionDispatch
module SystemTesting
class Driver # :nodoc:
def initialize(name, **options)
@name = name
@browser = options[:using]
@screen_size = options[:screen_size]
@options = options[:options]
end
def use
register if selenium?
setup
end
private
def selenium?
@name == :selenium
end
def register
Capybara.register_driver @name do |app|
Capybara::Selenium::Driver.new(app, { browser: @browser }.merge(@options)).tap do |driver|
driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
end
end
end
def setup
Capybara.current_driver = @name
end
end
end
end