Skip to content

Commit

Permalink
Merge PR #48950
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Aug 21, 2023
2 parents ae20b0d + 72c5270 commit 24876e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,7 @@
* Add support for Playwright as a driver for system tests.

*Yuki Nishijima*

* Fix `HostAuthorization` potentially displaying the value of the
X_FORWARDED_HOST header when the HTTP_HOST header is being blocked.

Expand Down
14 changes: 13 additions & 1 deletion actionpack/lib/action_dispatch/system_testing/driver.rb
Expand Up @@ -30,7 +30,7 @@ def use

private
def registerable?
[:selenium, :cuprite, :rack_test].include?(@driver_type)
[:selenium, :cuprite, :rack_test, :playwright].include?(@driver_type)
end

def register
Expand All @@ -41,6 +41,7 @@ def register
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
Expand All @@ -63,6 +64,17 @@ def register_rack_test(app)
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
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/dispatch/system_testing/driver_test.rb
Expand Up @@ -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")
Expand Down

0 comments on commit 24876e6

Please sign in to comment.