diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 14efc7214..9fc95a26a 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -29,30 +29,19 @@ Capybara.register_driver :chrome do |app| options.add_argument('--no-sandbox') unless ENV['SANDBOX'] options.add_argument('--mute-audio') options.add_argument('--window-size=1440,900') + options.add_argument('--disable-search-engine-choice-screen') + if ENV['NO_HEADLESS'].blank? + options.add_argument('--headless') + options.add_argument('--disable-dev-shm-usage') + options.add_argument('--disable-software-rasterizer') + end download_path = Capybara.save_path # Chromedriver 77 requires setting this for headless mode on linux # Different versions of Chrome/selenium-webdriver require setting differently - just set them all options.add_preference('download.default_directory', download_path) options.add_preference(:download, default_directory: download_path) - - setup_driver(app, download_path, options) -end - -Capybara.register_driver :headless_chrome do |app| - options = Selenium::WebDriver::Chrome::Options.new - options.add_argument('--no-sandbox') unless ENV['SANDBOX'] - options.add_argument('--headless') - options.add_argument('--window-size=1440,900') - options.add_argument('--disable-dev-shm-usage') - options.add_argument('--disable-software-rasterizer') - options.add_argument('--mute-audio') - - download_path = Capybara.save_path - # Chromedriver 77 requires setting this for headless mode on linux - # Different versions of Chrome/selenium-webdriver require setting differently - just set them all - options.add_preference('download.default_directory', download_path) - options.add_preference(:download, default_directory: download_path) + options.add_preference('intl.accept_languages', 'fr') setup_driver(app, download_path, options) end @@ -69,9 +58,9 @@ Capybara.disable_animation = true Capybara::Screenshot.autosave_on_failure = true # Keep only the screenshots generated from the last failing test suite Capybara::Screenshot.prune_strategy = :keep_last_run -# Tell Capybara::Screenshot how to take screenshots when using the headless_chrome driver -Capybara::Screenshot.register_driver :headless_chrome do |driver, path| - driver.browser.save_screenshot(path) +# Tell Capybara::Screenshot how to take screenshots when using the chrome driver +Capybara::Screenshot.register_driver :chrome do |driver, path| + driver.save_screenshot(path) end RSpec.configure do |config| @@ -80,21 +69,7 @@ RSpec.configure do |config| end config.before(:each, type: :system, js: true) do - driven_by ENV['NO_HEADLESS'] ? :chrome : :headless_chrome - end - - # Set the user preferred language before Javascript system specs. - # - # System specs without Javascript run in a Rack stack, and respect the Accept-Language value. - # However specs using Javascript are run into a Headless Chrome, which doesn't support setting - # the default Accept-Language value reliably. - # So instead we set the locale cookie explicitly before each Javascript test. - config.before(:each, type: :system, js: true) do - visit '/' # Webdriver needs visiting a page before setting the cookie - Capybara.current_session.driver.browser.manage.add_cookie( - name: :locale, - value: Rails.application.config.i18n.default_locale - ) + driven_by :chrome end # Examples tagged with :capybara_ignore_server_errors will allow Capybara diff --git a/spec/system/administrateurs/annotations_spec.rb b/spec/system/administrateurs/annotations_spec.rb index 68588cafa..7bfa87e1d 100644 --- a/spec/system/administrateurs/annotations_spec.rb +++ b/spec/system/administrateurs/annotations_spec.rb @@ -29,7 +29,7 @@ describe 'As an administrateur I can edit annotation', js: true do select('Titre de niveau 2', from: dom_id(second_header, :header_section_level)) within(".types-de-champ-block li:first-child") do - page.accept_alert do + accept_alert do click_on 'Supprimer' end end diff --git a/spec/system/administrateurs/condition_spec.rb b/spec/system/administrateurs/condition_spec.rb index a6fd7ef7b..09c946d25 100644 --- a/spec/system/administrateurs/condition_spec.rb +++ b/spec/system/administrateurs/condition_spec.rb @@ -39,8 +39,9 @@ describe 'As an administrateur I can edit types de champ condition', js: true do scenario "the first type de champ is removed" do within '.type-de-champ:nth-child(1)' do - click_on 'Supprimer' - page.accept_alert + accept_alert do + click_on 'Supprimer' + end end # the condition table is deleted @@ -56,8 +57,9 @@ describe 'As an administrateur I can edit types de champ condition', js: true do scenario "removing all conditions" do within '.type-de-champ:nth-child(2)' do - click_on 'cliquer pour désactiver' - page.accept_alert + accept_alert do + click_on 'cliquer pour désactiver' + end # the condition table is deleted expect(page).to have_no_table diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index e8ffd19ee..c1b6b94e5 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -55,7 +55,7 @@ describe 'As an administrateur I can edit types de champ', js: true do # Champs can be deleted within '.type-de-champ:nth-child(3)' do - page.accept_alert do + accept_alert do click_on 'Supprimer' end end @@ -80,7 +80,7 @@ describe 'As an administrateur I can edit types de champ', js: true do page.refresh - page.accept_alert do + accept_alert do click_on 'Supprimer' end expect(page).to have_content('Formulaire enregistré') @@ -186,7 +186,7 @@ describe 'As an administrateur I can edit types de champ', js: true do expect(page).to have_content('Durée de remplissage estimée : 2 min') # It updates the estimate when removing the champ - page.accept_alert do + accept_alert do click_on 'Supprimer' end expect(page).not_to have_content('Durée de remplissage estimée') @@ -226,7 +226,7 @@ describe 'As an administrateur I can edit types de champ', js: true do select('Titre de niveau 2', from: dom_id(second_header, :header_section_level)) within(".types-de-champ-block li:first-child") do - page.accept_alert do + accept_alert do click_on 'Supprimer' end end @@ -393,13 +393,16 @@ describe 'As an administrateur I can edit types de champ', js: true do expect(page).to have_button('Publier les modifications', disabled: true) # Supprime dernier champ - all('.fr-btn--tertiary-no-outline[title="Supprimer le champ"]').last.click - page.driver.browser.switch_to.alert.accept rescue nil + accept_alert do + all('.fr-btn--tertiary-no-outline[title="Supprimer le champ"]').last.click + end expect(page).to have_selector('.type-de-champ', count: 1, wait: 5) - click_on "Publier les modifications" - page.driver.browser.switch_to.alert.accept + accept_alert do + click_on "Publier les modifications" + end + expect(page).to have_content("démarche publiée") unpublished_procedure = create(:procedure) diff --git a/spec/system/instructeurs/batch_operation_spec.rb b/spec/system/instructeurs/batch_operation_spec.rb index 8428f3118..2e73157c1 100644 --- a/spec/system/instructeurs/batch_operation_spec.rb +++ b/spec/system/instructeurs/batch_operation_spec.rb @@ -34,7 +34,7 @@ describe 'BatchOperation a dossier:', js: true do # ensure batch is created - page.accept_alert do + accept_alert do click_on "Archiver les dossiers" end @@ -76,7 +76,7 @@ describe 'BatchOperation a dossier:', js: true do end # submit checkall - page.accept_alert do + accept_alert do click_on "Archiver les dossiers" end diff --git a/spec/system/instructeurs/instruction_spec.rb b/spec/system/instructeurs/instruction_spec.rb index c948fa1d1..220949a4d 100644 --- a/spec/system/instructeurs/instruction_spec.rb +++ b/spec/system/instructeurs/instruction_spec.rb @@ -145,7 +145,7 @@ describe 'Instructing a dossier:', js: true do perform_enqueued_jobs(only: ExportJob) end - page.driver.browser.navigate.refresh + page.refresh expect(page).to have_text('Télécharger l’export') end diff --git a/spec/system/users/list_dossiers_spec.rb b/spec/system/users/list_dossiers_spec.rb index d423f2635..be9ecc6c0 100644 --- a/spec/system/users/list_dossiers_spec.rb +++ b/spec/system/users/list_dossiers_spec.rb @@ -189,7 +189,7 @@ describe 'user access to the list of their dossiers', js: true do expect(page).to have_content(dossier_en_construction.procedure.libelle) within(:css, ".card", match: :first) do click_on 'Autres actions' - page.accept_alert('Confirmer la suppression ?') do + accept_alert('Confirmer la suppression ?') do click_on 'Supprimer le dossier' end end