Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use playwright driver #10720

Merged
merged 6 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -899,6 +906,7 @@ DEPENDENCIES
browser
capybara
capybara-email
capybara-playwright-driver
capybara-screenshot
charlock_holmes
chartkick
Expand Down
1 change: 1 addition & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -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 =="
Expand Down
16 changes: 16 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -62,13 +70,21 @@ def setup_driver(app, download_path, options)
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
driven_by :rack_test
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

Expand Down
7 changes: 7 additions & 0 deletions spec/support/system_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def blur
end
end

def playwright_debug
page.driver.with_playwright_page do |page|
page.context.enable_debug_console!
page.pause
end
end

def pause
$stderr.write 'Spec paused. Press enter to continue:'
$stdin.gets
Expand Down
2 changes: 1 addition & 1 deletion spec/system/accessibilite/wcag_usager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'wcag rules for usager', js: true do
describe 'wcag rules for usager', chrome: true do
let(:procedure) { create(:procedure, :published, :with_service, :for_individual) }
let(:password) { 'a very complicated password' }
let(:litteraire_user) { create(:user, password: password) }
Expand Down
2 changes: 1 addition & 1 deletion spec/system/administrateurs/admin_creation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end
end

scenario 'I can register', js: true do
scenario 'I can register' do
expect(new_admin.reload.user.active?).to be(false)

confirmation_email = open_email(admin_email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def find_attestation_card(with_nested_selector: nil)
}

fill_in "Contenu du pied de page", with: ["line1", "line2", "line3", "line4"].join("\n")
expect(page).to have_field("Contenu du pied de page", with: "line1\nline2\nline3line4")
# FIXME we should get line1\nline2\nline3line4 instead of line1\nline2\nline3\nline4 because row is set to 3
expect(page).to have_field("Contenu du pied de page", with: "line1\nline2\nline3\nline4")

click_on "Publier"
expect(attestation.reload).to be_published
Expand Down
5 changes: 1 addition & 4 deletions spec/system/experts/expert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@
click_on '1 avis à donner'
click_on avis.dossier.user.email

# click_on 'Télécharger le dossier et toutes ses pièces jointes'
# For some reason, clicking the download link does not trigger the download in the headless browser
# for some member of the team, so we need to go to the download link directly
visit telecharger_pjs_expert_avis_path(avis.dossier.procedure, avis)
click_on 'Télécharger le dossier et toutes ses pièces jointes'

DownloadHelpers.wait_for_download
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
Expand Down
2 changes: 1 addition & 1 deletion spec/system/instructeurs/batch_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:procedure) { create(:simple_procedure, :published, instructeurs: [instructeur], administrateurs: [administrateurs(:default_admin)]) }

context 'with an instructeur' do
scenario 'create a BatchOperation' do
scenario 'create a BatchOperation', chrome: true do
dossier_1 = create(:dossier, :accepte, procedure: procedure)
dossier_2 = create(:dossier, :accepte, procedure: procedure)
dossier_3 = create(:dossier, :accepte, procedure: procedure)
Expand Down
14 changes: 7 additions & 7 deletions spec/system/instructeurs/instruction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
click_on 'Instruire le dossier'

within('.instruction-button') do
click_on 'Accepter'
# FIXME click_on 'Accepter' is not working for some reason
find_link('Accepter').click
end

within('.accept.motivation') do
Expand Down Expand Up @@ -210,7 +211,7 @@
expect(Archive.first.month).not_to be_nil
end
end
context 'with dossiers having attached files', js: true do
context 'with dossiers having attached files' do
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }], instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:champ) { dossier.champs_public.first }
Expand All @@ -231,10 +232,7 @@

scenario 'A instructeur can download an archive containing a single attachment' do
find(:css, '[aria-controls=print-pj-menu]').click
# click_on 'Télécharger le dossier et toutes ses pièces jointes'
# For some reason, clicking the download link does not trigger the download in the headless browser
# for some member of the team, so we need to go to the download link directly
visit telecharger_pjs_instructeur_dossier_path(procedure, dossier)
click_on 'Télécharger le dossier et toutes ses pièces jointes'

DownloadHelpers.wait_for_download
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
Expand All @@ -254,7 +252,9 @@
content_type: "application/pdf",
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE })

visit telecharger_pjs_instructeur_dossier_path(procedure, dossier)
find(:css, '[aria-controls=print-pj-menu]').click
click_on 'Télécharger le dossier et toutes ses pièces jointes'

DownloadHelpers.wait_for_download
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))

Expand Down
6 changes: 3 additions & 3 deletions spec/system/instructeurs/procedure_filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
end
end

scenario "should add be able to add created_at column", js: true do
scenario "should add be able to add created_at column", chrome: true do
add_column("Créé le")
within ".dossiers-table" do
expect(page).to have_link("Créé le")
expect(page).to have_link(new_unfollow_dossier.created_at.strftime('%d/%m/%Y'))
end
end

scenario "should add be able to add and remove custom type_de_champ column", js: true do
scenario "should add be able to add and remove custom type_de_champ column", chrome: true do
add_column(type_de_champ.libelle)
within ".dossiers-table" do
expect(page).to have_link(type_de_champ.libelle)
Expand Down Expand Up @@ -206,7 +206,7 @@ def add_filter(column_name, filter_value, type: :text)
fill_in "Valeur", with: filter_value
when :date
find("input#value[type=date]", visible: true)
fill_in "Valeur", with: filter_value
fill_in "Valeur", with: Date.parse(filter_value)
when :enum
find("select#value", visible: false)
select filter_value, from: "Valeur"
Expand Down
Loading
Loading