mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #29315 from mariochavez/driven_by_support_headless_drivers
SystemTesting::Driver can register capybara-webkit and poltergeist
This commit is contained in:
parent
4d00d543c7
commit
c5dd45119a
5 changed files with 61 additions and 11 deletions
|
@ -1,3 +1,15 @@
|
||||||
|
* `driven_by` now registers poltergeist and capybara-webkit
|
||||||
|
|
||||||
|
If driver poltergeist or capybara-webkit is set for System Tests,
|
||||||
|
`driven_by` will register the driver and set additional options passed via
|
||||||
|
`:options` param.
|
||||||
|
|
||||||
|
Refer to drivers documentation to learn what options can be passed.
|
||||||
|
|
||||||
|
*Mario Chavez*
|
||||||
|
|
||||||
|
* AEAD encrypted cookies and sessions with GCM
|
||||||
|
|
||||||
## Rails 5.1.1 (May 12, 2017) ##
|
## Rails 5.1.1 (May 12, 2017) ##
|
||||||
|
|
||||||
* No changes.
|
* No changes.
|
||||||
|
|
|
@ -67,13 +67,17 @@ module ActionDispatch
|
||||||
# To use a headless driver, like Poltergeist, update your Gemfile to use
|
# To use a headless driver, like Poltergeist, update your Gemfile to use
|
||||||
# Poltergeist instead of Selenium and then declare the driver name in the
|
# Poltergeist instead of Selenium and then declare the driver name in the
|
||||||
# +application_system_test_case.rb+ file. In this case you would leave out the +:using+
|
# +application_system_test_case.rb+ file. In this case you would leave out the +:using+
|
||||||
# option because the driver is headless.
|
# option because the driver is headless, but you can still use
|
||||||
|
# +:screen_size+ to change the size of the browser screen, also you can use
|
||||||
|
# +:options+ to pass options supported by the driver. Please refeer to your
|
||||||
|
# driver documentation to learn about supported options.
|
||||||
#
|
#
|
||||||
# require "test_helper"
|
# require "test_helper"
|
||||||
# require "capybara/poltergeist"
|
# require "capybara/poltergeist"
|
||||||
#
|
#
|
||||||
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||||
# driven_by :poltergeist
|
# driven_by :poltergeist, screen_size: [1400, 1400], options:
|
||||||
|
# { js_errors: true }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara
|
# Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara
|
||||||
|
|
|
@ -9,23 +9,42 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def use
|
def use
|
||||||
register if selenium?
|
register unless rack_test?
|
||||||
|
|
||||||
setup
|
setup
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def selenium?
|
def rack_test?
|
||||||
@name == :selenium
|
@name == :rack_test
|
||||||
end
|
end
|
||||||
|
|
||||||
def register
|
def register
|
||||||
Capybara.register_driver @name do |app|
|
Capybara.register_driver @name do |app|
|
||||||
Capybara::Selenium::Driver.new(app, { browser: @browser }.merge(@options)).tap do |driver|
|
case @name
|
||||||
driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
|
when :selenium then register_selenium(app)
|
||||||
|
when :poltergeist then register_poltergeist(app)
|
||||||
|
when :webkit then register_webkit(app)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_selenium(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
|
||||||
|
|
||||||
|
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(*@screen_size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Capybara.current_driver = @name
|
Capybara.current_driver = @name
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,21 @@ class DriverTest < ActiveSupport::TestCase
|
||||||
assert_equal ({ url: "http://example.com/wd/hub" }), driver.instance_variable_get(:@options)
|
assert_equal ({ url: "http://example.com/wd/hub" }), driver.instance_variable_get(:@options)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "selenium? returns false if driver is poltergeist" do
|
test "initializing the driver with a poltergeist" do
|
||||||
assert_not ActionDispatch::SystemTesting::Driver.new(:poltergeist).send(:selenium?)
|
driver = ActionDispatch::SystemTesting::Driver.new(:poltergeist, screen_size: [1400, 1400], options: { js_errors: false })
|
||||||
|
assert_equal :poltergeist, driver.instance_variable_get(:@name)
|
||||||
|
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
|
||||||
|
assert_equal ({ js_errors: false }), driver.instance_variable_get(:@options)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "initializing the driver with a webkit" do
|
||||||
|
driver = ActionDispatch::SystemTesting::Driver.new(:webkit, screen_size: [1400, 1400], options: { skip_image_loading: true })
|
||||||
|
assert_equal :webkit, driver.instance_variable_get(:@name)
|
||||||
|
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
|
||||||
|
assert_equal ({ skip_image_loading: true }), driver.instance_variable_get(:@options)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rack_test? returns false if driver is poltergeist" do
|
||||||
|
assert_not ActionDispatch::SystemTesting::Driver.new(:poltergeist).send(:rack_test?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -658,8 +658,9 @@ end
|
||||||
|
|
||||||
The driver name is a required argument for `driven_by`. The optional arguments
|
The driver name is a required argument for `driven_by`. The optional arguments
|
||||||
that can be passed to `driven_by` are `:using` for the browser (this will only
|
that can be passed to `driven_by` are `:using` for the browser (this will only
|
||||||
be used by Selenium), and `:screen_size` to change the size of the screen for
|
be used by Selenium), `:screen_size` to change the size of the screen for
|
||||||
screenshots.
|
screenshots, and `:options` which can be used to set options supported by the
|
||||||
|
driver.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
Loading…
Reference in a new issue