use playwright driver

This commit is contained in:
Paul Chavard 2024-09-10 23:53:25 +02:00
parent 7b1c882498
commit 142c789e76
No known key found for this signature in database
5 changed files with 29 additions and 0 deletions

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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 =="

View file

@ -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