From 142c789e76f6bdfb36ae2cf26f755a75ae901cd8 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 10 Sep 2024 23:53:25 +0200 Subject: [PATCH] use playwright driver --- .github/workflows/ci.yml | 3 +++ Gemfile | 1 + Gemfile.lock | 8 ++++++++ bin/setup | 1 + spec/support/capybara.rb | 16 ++++++++++++++++ 5 files changed, 29 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89d52a61d..59441d97d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,6 +137,9 @@ jobs: - name: Setup the app runtime and dependencies uses: ./.github/actions/ci-setup-rails + - name: Setup playwright + run: bunx playwright install chromium + - name: Pre-compile assets uses: ./.github/actions/ci-setup-assets diff --git a/Gemfile b/Gemfile index 0a44993e6..33db0435e 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem 'anchored' gem 'bcrypt' gem 'bootsnap', '>= 1.4.4', require: false # Reduces boot times through caching; required in config/boot.rb gem 'browser' +gem 'capybara-playwright-driver' gem 'charlock_holmes' gem 'chartkick' gem 'chunky_png' diff --git a/Gemfile.lock b/Gemfile.lock index 386d6bb5f..a26a07127 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -157,6 +157,10 @@ GEM capybara-email (3.0.2) capybara (>= 2.4, < 4.0) mail + capybara-playwright-driver (0.5.2) + addressable + capybara + playwright-ruby-client (>= 1.16.0) capybara-screenshot (1.0.26) capybara (>= 1.0, < 4) launchy @@ -483,6 +487,9 @@ GEM pdf-core (0.9.0) pg (1.5.6) phonelib (0.8.8) + playwright-ruby-client (1.46.0) + concurrent-ruby (>= 1.1.6) + mime-types (>= 3.0) prawn (2.4.0) pdf-core (~> 0.9.0) ttfunk (~> 1.7) @@ -899,6 +906,7 @@ DEPENDENCIES browser capybara capybara-email + capybara-playwright-driver capybara-screenshot charlock_holmes chartkick diff --git a/bin/setup b/bin/setup index 9b8efb38d..22286e576 100755 --- a/bin/setup +++ b/bin/setup @@ -20,6 +20,7 @@ FileUtils.chdir APP_ROOT do # Install JavaScript dependencies system! 'bun --version' system! 'bun install' + system! 'bunx playwright install chromium' if ENV["UPDATE_WEBDRIVER"] puts "\n== Updating webdrivers ==" diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 9fc95a26a..ef5032adf 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -24,6 +24,14 @@ def setup_driver(app, download_path, options) end end +Capybara.register_driver :playwright do |app| + Capybara::Playwright::Driver.new(app, + browser_type: (ENV['PLAYWRIGHT_BROWSER'] || 'chromium').to_sym, # :chromium (default) or :firefox, :webkit + headless: ENV['NO_HEADLESS'].blank?, + locale: Rails.application.config.i18n.default_locale, + downloadsPath: Capybara.save_path) +end + Capybara.register_driver :chrome do |app| options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--no-sandbox') unless ENV['SANDBOX'] @@ -62,6 +70,10 @@ Capybara::Screenshot.prune_strategy = :keep_last_run Capybara::Screenshot.register_driver :chrome do |driver, path| driver.save_screenshot(path) end +# Tell Capybara::Screenshot how to take screenshots when using the playwright driver +Capybara::Screenshot.register_driver :playwright do |driver, path| + driver.save_screenshot(path) +end RSpec.configure do |config| config.before(:each, type: :system) do @@ -69,6 +81,10 @@ RSpec.configure do |config| end config.before(:each, type: :system, js: true) do + driven_by :playwright + end + + config.before(:each, type: :system, chrome: true) do driven_by :chrome end