mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42790 from YusukeIwaki/replace_poltergeist_with_cuprite
Deprecate `poltergeist` and `webkit` driver registration. Add `cuprite`.
This commit is contained in:
commit
e43d0ddb03
5 changed files with 44 additions and 12 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
* Deprecate `poltergeist` and `webkit` (capybara-webkit) driver registration for system testing (they will be removed in Rails 7.1). Add `cuprite` instead.
|
||||||
|
|
||||||
|
[Poltergeist](https://github.com/teampoltergeist/poltergeist) and [capybara-webkit](https://github.com/thoughtbot/capybara-webkit) are already not maintained. These usage in Rails are removed for avoiding confusing users.
|
||||||
|
|
||||||
|
[Cuprite](https://github.com/rubycdp/cuprite) is a good alternative to Poltergeist. Some guide descriptions are replaced from Poltergeist to Cuprite.
|
||||||
|
|
||||||
|
*Yusuke Iwaki*
|
||||||
|
|
||||||
* Add `Middleware#remove` to delete middleware or raise if not found.
|
* Add `Middleware#remove` to delete middleware or raise if not found.
|
||||||
|
|
||||||
`Middleware#remove` works just like `Middleware#delete` but will
|
`Middleware#remove` works just like `Middleware#delete` but will
|
||||||
|
|
|
@ -72,8 +72,8 @@ module ActionDispatch
|
||||||
# Headless browsers such as headless Chrome and headless Firefox are also supported.
|
# Headless browsers such as headless Chrome and headless Firefox are also supported.
|
||||||
# You can use these browsers by setting the +:using+ argument to +:headless_chrome+ or +:headless_firefox+.
|
# You can use these browsers by setting the +:using+ argument to +:headless_chrome+ or +:headless_firefox+.
|
||||||
#
|
#
|
||||||
# To use a headless driver, like Poltergeist, update your Gemfile to use
|
# To use a headless driver, like Cuprite, update your Gemfile to use
|
||||||
# Poltergeist instead of Selenium and then declare the driver name in the
|
# Cuprite instead of Selenium and then declare the driver name in the
|
||||||
# +application_system_test_case.rb+ file. In this case, you would leave out
|
# +application_system_test_case.rb+ file. In this case, you would leave out
|
||||||
# the +:using+ option because the driver is headless, but you can still use
|
# the +:using+ 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
|
# +:screen_size+ to change the size of the browser screen, also you can use
|
||||||
|
@ -81,10 +81,10 @@ module ActionDispatch
|
||||||
# driver documentation to learn about supported options.
|
# driver documentation to learn about supported options.
|
||||||
#
|
#
|
||||||
# require "test_helper"
|
# require "test_helper"
|
||||||
# require "capybara/poltergeist"
|
# require "capybara/cuprite"
|
||||||
#
|
#
|
||||||
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||||
# driven_by :poltergeist, screen_size: [1400, 1400], options:
|
# driven_by :cuprite, screen_size: [1400, 1400], options:
|
||||||
# { js_errors: true }
|
# { js_errors: true }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
@ -140,7 +140,7 @@ module ActionDispatch
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
#
|
#
|
||||||
# driven_by :poltergeist
|
# driven_by :cuprite
|
||||||
#
|
#
|
||||||
# driven_by :selenium, screen_size: [800, 800]
|
# driven_by :selenium, screen_size: [800, 800]
|
||||||
#
|
#
|
||||||
|
|
|
@ -9,6 +9,14 @@ module ActionDispatch
|
||||||
@options = options[:options] || {}
|
@options = options[:options] || {}
|
||||||
@capabilities = capabilities
|
@capabilities = capabilities
|
||||||
|
|
||||||
|
if [:poltergeist, :webkit].include?(name)
|
||||||
|
ActiveSupport::Deprecation.warn <<~MSG.squish
|
||||||
|
Poltergeist and capybara-webkit are not maintained already.
|
||||||
|
Driver registration of :poltergeist or :webkit is deprecated and will be removed in Rails 7.1.
|
||||||
|
You can still use :selenium, and also :cuprite is available for alternative to Poltergeist.
|
||||||
|
MSG
|
||||||
|
end
|
||||||
|
|
||||||
if name == :selenium
|
if name == :selenium
|
||||||
require "selenium/webdriver"
|
require "selenium/webdriver"
|
||||||
@browser = Browser.new(options[:using])
|
@browser = Browser.new(options[:using])
|
||||||
|
@ -26,7 +34,7 @@ module ActionDispatch
|
||||||
|
|
||||||
private
|
private
|
||||||
def registerable?
|
def registerable?
|
||||||
[:selenium, :poltergeist, :webkit, :rack_test].include?(@name)
|
[:selenium, :poltergeist, :webkit, :cuprite, :rack_test].include?(@name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def register
|
def register
|
||||||
|
@ -37,6 +45,7 @@ module ActionDispatch
|
||||||
when :selenium then register_selenium(app)
|
when :selenium then register_selenium(app)
|
||||||
when :poltergeist then register_poltergeist(app)
|
when :poltergeist then register_poltergeist(app)
|
||||||
when :webkit then register_webkit(app)
|
when :webkit then register_webkit(app)
|
||||||
|
when :cuprite then register_cuprite(app)
|
||||||
when :rack_test then register_rack_test(app)
|
when :rack_test then register_rack_test(app)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -62,6 +71,10 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_cuprite(app)
|
||||||
|
Capybara::Cuprite::Driver.new(app, @options.merge(window_size: @screen_size))
|
||||||
|
end
|
||||||
|
|
||||||
def register_rack_test(app)
|
def register_rack_test(app)
|
||||||
Capybara::RackTest::Driver.new(app, respect_data_method: true, **@options)
|
Capybara::RackTest::Driver.new(app, respect_data_method: true, **@options)
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,19 +38,30 @@ class DriverTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "initializing the driver with a poltergeist" do
|
test "initializing the driver with a poltergeist" do
|
||||||
driver = ActionDispatch::SystemTesting::Driver.new(:poltergeist, screen_size: [1400, 1400], options: { js_errors: false })
|
driver = assert_deprecated do
|
||||||
|
ActionDispatch::SystemTesting::Driver.new(:poltergeist, screen_size: [1400, 1400], options: { js_errors: false })
|
||||||
|
end
|
||||||
assert_equal :poltergeist, driver.instance_variable_get(:@name)
|
assert_equal :poltergeist, driver.instance_variable_get(:@name)
|
||||||
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
|
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
|
||||||
assert_equal ({ js_errors: false }), driver.instance_variable_get(:@options)
|
assert_equal ({ js_errors: false }), driver.instance_variable_get(:@options)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "initializing the driver with a webkit" do
|
test "initializing the driver with a webkit" do
|
||||||
driver = ActionDispatch::SystemTesting::Driver.new(:webkit, screen_size: [1400, 1400], options: { skip_image_loading: true })
|
driver = assert_deprecated do
|
||||||
|
ActionDispatch::SystemTesting::Driver.new(:webkit, screen_size: [1400, 1400], options: { skip_image_loading: true })
|
||||||
|
end
|
||||||
assert_equal :webkit, driver.instance_variable_get(:@name)
|
assert_equal :webkit, driver.instance_variable_get(:@name)
|
||||||
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
|
assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size)
|
||||||
assert_equal ({ skip_image_loading: true }), driver.instance_variable_get(:@options)
|
assert_equal ({ skip_image_loading: true }), driver.instance_variable_get(:@options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "initializing the driver with a cuprite" do
|
||||||
|
driver = ActionDispatch::SystemTesting::Driver.new(:cuprite, screen_size: [1400, 1400], options: { js_errors: false })
|
||||||
|
assert_equal :cuprite, 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 "define extra capabilities using chrome" do
|
test "define extra capabilities using chrome" do
|
||||||
driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :chrome) do |option|
|
driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :chrome) do |option|
|
||||||
option.add_argument("start-maximized")
|
option.add_argument("start-maximized")
|
||||||
|
@ -153,6 +164,6 @@ class DriverTest < ActiveSupport::TestCase
|
||||||
assert ActionDispatch::SystemTesting::Driver.new(:selenium).instance_variable_get(:@browser)
|
assert ActionDispatch::SystemTesting::Driver.new(:selenium).instance_variable_get(:@browser)
|
||||||
|
|
||||||
assert_nil ActionDispatch::SystemTesting::Driver.new(:rack_test).instance_variable_get(:@browser)
|
assert_nil ActionDispatch::SystemTesting::Driver.new(:rack_test).instance_variable_get(:@browser)
|
||||||
assert_nil ActionDispatch::SystemTesting::Driver.new(:poltergeist).instance_variable_get(:@browser)
|
assert_nil ActionDispatch::SystemTesting::Driver.new(:cuprite).instance_variable_get(:@browser)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -825,15 +825,15 @@ system tests should live.
|
||||||
|
|
||||||
If you want to change the default settings you can change what the system
|
If you want to change the default settings you can change what the system
|
||||||
tests are "driven by". Say you want to change the driver from Selenium to
|
tests are "driven by". Say you want to change the driver from Selenium to
|
||||||
Poltergeist. First add the `poltergeist` gem to your `Gemfile`. Then in your
|
Cuprite. First add the `cuprite` gem to your `Gemfile`. Then in your
|
||||||
`application_system_test_case.rb` file do the following:
|
`application_system_test_case.rb` file do the following:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
require "capybara/poltergeist"
|
require "capybara/cuprite"
|
||||||
|
|
||||||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||||
driven_by :poltergeist
|
driven_by :cuprite
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue