Merge pull request #10775 from tchak/improuve-chromedriver-config

spec(selenium): improve chromedriver config
This commit is contained in:
Paul Chavard 2024-09-12 18:46:11 +00:00 committed by GitHub
commit 7286fb9ef2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 33 additions and 53 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 lexport')
end

View file

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