Merge pull request #7969 from demarches-simplifiees/more_stable_system_spec
fix(spec/system): stabilise encore un peu les tests de bout en bout
This commit is contained in:
commit
cde1aebe5e
4 changed files with 38 additions and 19 deletions
|
@ -122,6 +122,10 @@ Pour exécuter les tests de l'application, plusieurs possibilités :
|
|||
|
||||
JS_LOG=error bin/rspec spec/system
|
||||
|
||||
- Augmenter la latence lors de tests end2end pour déceler des bugs récalcitrants
|
||||
|
||||
MAKE_IT_SLOW=1 bin/rspec spec/system
|
||||
|
||||
### Ajout de taches à exécuter au déploiement
|
||||
|
||||
rails generate after_party:task task_name
|
||||
|
|
|
@ -3,6 +3,28 @@ require 'capybara-screenshot/rspec'
|
|||
require 'capybara/email/rspec'
|
||||
require 'selenium/webdriver'
|
||||
|
||||
def setup_driver(app, download_path, options)
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options:).tap do |driver|
|
||||
# Set download dir for Chrome < 77
|
||||
driver.browser.download_path = download_path
|
||||
|
||||
if ENV['MAKE_IT_SLOW'].present?
|
||||
driver.browser.network_conditions = {
|
||||
offline: false,
|
||||
latency: 800,
|
||||
download_throughput: 1024000,
|
||||
upload_throughput: 1024000
|
||||
}
|
||||
end
|
||||
|
||||
if ENV['JS_LOG'].present?
|
||||
driver.browser.on_log_event(:console) do |event|
|
||||
puts event.args if event.type == ENV['JS_LOG'].downcase.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.register_driver :chrome do |app|
|
||||
options = Selenium::WebDriver::Chrome::Options.new
|
||||
options.add_argument('--no-sandbox') unless ENV['SANDBOX']
|
||||
|
@ -15,10 +37,7 @@ Capybara.register_driver :chrome do |app|
|
|||
options.add_preference('download.default_directory', download_path)
|
||||
options.add_preference(:download, default_directory: download_path)
|
||||
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options).tap do |driver|
|
||||
# Set download dir for Chrome < 77
|
||||
driver.browser.download_path = download_path
|
||||
end
|
||||
setup_driver(app, download_path, options)
|
||||
end
|
||||
|
||||
Capybara.register_driver :headless_chrome do |app|
|
||||
|
@ -36,10 +55,7 @@ Capybara.register_driver :headless_chrome do |app|
|
|||
options.add_preference('download.default_directory', download_path)
|
||||
options.add_preference(:download, default_directory: download_path)
|
||||
|
||||
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options).tap do |driver|
|
||||
# Set download dir for Chrome < 77
|
||||
driver.browser.download_path = download_path
|
||||
end
|
||||
setup_driver(app, download_path, options)
|
||||
end
|
||||
|
||||
Capybara.default_max_wait_time = 2
|
||||
|
@ -66,12 +82,6 @@ RSpec.configure do |config|
|
|||
|
||||
config.before(:each, type: :system, js: true) do
|
||||
driven_by ENV['NO_HEADLESS'] ? :chrome : :headless_chrome
|
||||
|
||||
if ENV['JS_LOG'].present?
|
||||
page.driver.browser.on_log_event(:console) do |event|
|
||||
puts event.args if event.type == ENV['JS_LOG'].downcase.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Set the user preferred language before Javascript system specs.
|
||||
|
|
|
@ -290,6 +290,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
click_on 'Déposer le dossier'
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
|
||||
|
||||
visit demande_dossier_path(dossier)
|
||||
expect(page).to have_content(/Des données.*ont été reçues depuis la CAF/)
|
||||
|
@ -344,6 +345,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
click_on 'Déposer le dossier'
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
|
||||
|
||||
visit demande_dossier_path(dossier)
|
||||
expect(page).to have_content(/Des données.*ont été reçues depuis Pôle emploi/)
|
||||
|
@ -413,6 +415,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
click_on 'Déposer le dossier'
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
|
||||
|
||||
visit demande_dossier_path(dossier)
|
||||
expect(page).to have_content(/Des données.*ont été reçues depuis le MESRI/)
|
||||
|
@ -475,6 +478,7 @@ describe 'fetch API Particulier Data', js: true do
|
|||
click_on 'Déposer le dossier'
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
|
||||
|
||||
visit demande_dossier_path(dossier)
|
||||
expect(page).to have_content(/Des données.*ont été reçues depuis la DGFiP/)
|
||||
|
|
|
@ -184,7 +184,7 @@ describe 'The user' do
|
|||
find_field('Pièce justificative 2').attach_file(Rails.root + 'spec/fixtures/files/RIB.pdf')
|
||||
|
||||
# Expect the files to be uploaded immediately
|
||||
expect(page).to have_text('analyse antivirus en cours', count: 2)
|
||||
expect(page).to have_text('analyse antivirus en cours', count: 2, wait: 5)
|
||||
expect(page).to have_text('file.pdf')
|
||||
expect(page).to have_text('RIB.pdf')
|
||||
|
||||
|
@ -206,7 +206,7 @@ describe 'The user' do
|
|||
# Test invalid file type
|
||||
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/invalid_file_format.json')
|
||||
expect(page).to have_no_text('La pièce justificative n’est pas d’un type accepté')
|
||||
expect(page).to have_text('analyse antivirus en cours', count: 1)
|
||||
expect(page).to have_text('analyse antivirus en cours', count: 1, wait: 5)
|
||||
end
|
||||
|
||||
scenario 'retry on transcient upload error', js: true do
|
||||
|
@ -219,15 +219,15 @@ describe 'The user' do
|
|||
instance.render json: { errors: ['Error'] }, status: :bad_request
|
||||
end
|
||||
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/file.pdf')
|
||||
expect(page).to have_text('Une erreur s’est produite pendant l’envoi du fichier')
|
||||
expect(page).to have_css('p', text: 'Le fichier n’a pas pu être envoyé', visible: :visible, wait: 5)
|
||||
expect(page).to have_button('Ré-essayer', visible: true)
|
||||
expect(page).to have_button('Déposer le dossier', disabled: false)
|
||||
|
||||
allow_any_instance_of(Champs::PieceJustificativeController).to receive(:update).and_call_original
|
||||
|
||||
# Test that retrying after a failure works
|
||||
click_on('Ré-essayer', visible: true)
|
||||
expect(page).to have_text('analyse antivirus en cours')
|
||||
click_on('Ré-essayer', visible: true, wait: 5)
|
||||
expect(page).to have_text('analyse antivirus en cours', wait: 5)
|
||||
expect(page).to have_text('file.pdf')
|
||||
expect(page).to have_button('Déposer le dossier', disabled: false)
|
||||
|
||||
|
@ -257,6 +257,7 @@ describe 'The user' do
|
|||
|
||||
click_on 'Déposer le dossier'
|
||||
|
||||
expect(page).to have_current_path(merci_dossier_path(user_dossier))
|
||||
expect(page).to have_text('Merci')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue