diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 385a5350f18..d4494b8042e 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add support for Playwright as a driver for system tests. + + *Yuki Nishijima* + * Rename `fixture_file_upload` method to `file_fixture_upload` Declare an alias to preserve the backwards compatibility of `fixture_file_upload` diff --git a/actionpack/lib/action_dispatch/system_testing/driver.rb b/actionpack/lib/action_dispatch/system_testing/driver.rb index 86c5ac66621..9a4fdeb73be 100644 --- a/actionpack/lib/action_dispatch/system_testing/driver.rb +++ b/actionpack/lib/action_dispatch/system_testing/driver.rb @@ -30,7 +30,7 @@ module ActionDispatch private def registerable? - [:selenium, :cuprite, :rack_test].include?(@driver_type) + [:selenium, :cuprite, :rack_test, :playwright].include?(@driver_type) end def register @@ -41,6 +41,7 @@ module ActionDispatch when :selenium then register_selenium(app) when :cuprite then register_cuprite(app) when :rack_test then register_rack_test(app) + when :playwright then register_playwright(app) end end end @@ -63,6 +64,17 @@ module ActionDispatch Capybara::RackTest::Driver.new(app, respect_data_method: true, **@options) end + def register_playwright(app) + screen = { width: @screen_size[0], height: @screen_size[1] } if @screen_size + options = { + screen: screen, + viewport: screen, + **@options + }.compact + + Capybara::Playwright::Driver.new(app, **options) + end + def setup Capybara.current_driver = name end diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb index b2e0871dd4d..92599ac0902 100644 --- a/actionpack/test/dispatch/system_testing/driver_test.rb +++ b/actionpack/test/dispatch/system_testing/driver_test.rb @@ -60,6 +60,14 @@ class DriverTest < ActiveSupport::TestCase assert_equal ({ js_errors: false }), driver.instance_variable_get(:@options) end + test "initializing the driver with Playwright" do + driver = ActionDispatch::SystemTesting::Driver.new(:playwright, screen_size: [1400, 1400], options: { headless: true }) + + assert_equal :playwright, driver.instance_variable_get(:@driver_type) + assert_equal [1400, 1400], driver.instance_variable_get(:@screen_size) + assert_equal ({ headless: true }), driver.instance_variable_get(:@options) + end + test "define extra capabilities using chrome" do driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :chrome) do |option| option.add_argument("start-maximized")