From f1c5aca087a7b0103dac73ddbd32c4b0a01aab38 Mon Sep 17 00:00:00 2001 From: Godwin Date: Mon, 5 Jun 2017 17:21:41 -0700 Subject: [PATCH] Implemented retries for failed scenarios --- Rakefile | 64 ++++++-------------- features/schedule.feature | 2 +- features/step_definitions/emails.rb | 22 ++++--- features/step_definitions/interface_steps.rb | 1 - tmp/locales/.gitkeep | 0 5 files changed, 32 insertions(+), 57 deletions(-) delete mode 100644 tmp/locales/.gitkeep diff --git a/Rakefile b/Rakefile index 7425d6e..6cd9773 100644 --- a/Rakefile +++ b/Rakefile @@ -89,61 +89,35 @@ task "cucumber:debug" do ENV['TEST_DEBUG'] = nil end -# Cucumber::Rake::Task.new(:cucumber) do |t| -# t.cucumber_opts = "features --format pretty" -# end - namespace :cucumber do - directory 'tmp' - @rerun_file = 'tmp/rerun.txt' + + FAILING_CUCUMBER_SCENARIOS_FILENAME = 'log/rerun.txt' - Cucumber::Rake::Task.new(:all) do |task| - task.cucumber_opts = "features --format pretty --format rerun --out tmp/rerun.txt" + Cucumber::Rake::Task.new(:start) do |task| + task.cucumber_opts = "features --format pretty -f rerun --out #{FAILING_CUCUMBER_SCENARIOS_FILENAME}" end - desc 'Run cucumber features' - task run: :tmp do - retry_on_failure do - run_features - end - clean_up - exit @exit_status + Cucumber::Rake::Task.new(:retry) do |task| + task.cucumber_opts = "@#{FAILING_CUCUMBER_SCENARIOS_FILENAME}" end - - def retry_on_failure - rm_rf @rerun_file - @retries = 0 + + task :run do + exception = nil begin - @exit_status = 0 - yield - rescue SystemExit => e - @exit_status = e.status - if retry?(exception: e) - @retries += 1 - retry + result = Rake::Task['cucumber:start'].execute + rescue Exception => e + begin + puts "\nRetrying failed scenarios...\n" + Rake::Task['cucumber:retry'].execute + rescue Exception => e2 + exception = e2 end end - end - def run_features - if File.exists? @rerun_file - Cucumber::Rake::Task::ForkedCucumberRunner.new(['lib'], Cucumber::BINARY, [ - 'features', - '--format', 'pretty', - '@tmp/rerun.txt', - '--format', 'rerun', - '--out', 'tmp/rerun.txt' - ], true, []).run - else - Rake::Task['cucumber:all'].invoke + if File.exists?("#{FAILING_CUCUMBER_SCENARIOS_FILENAME}") + File.delete("#{FAILING_CUCUMBER_SCENARIOS_FILENAME}") end - end - - def retry?(exception: nil) - @retries < 2 && !exception.success? - end - def clean_up - rm_rf @rerun_file.pathmap("%d") + raise exception unless exception.nil? end end diff --git a/features/schedule.feature b/features/schedule.feature index 24c5495..f6a4020 100644 --- a/features/schedule.feature +++ b/features/schedule.feature @@ -57,7 +57,7 @@ Feature: Conference Schedule When I click on 'Reaching New Immigrants' link Then I should see 'The Shop' And see '1027 Flatbush Ave' - And see 'More info' + And see 'Details' And see 'Close' When I click on the 'Close' button diff --git a/features/step_definitions/emails.rb b/features/step_definitions/emails.rb index 8edfe93..db1d4c0 100644 --- a/features/step_definitions/emails.rb +++ b/features/step_definitions/emails.rb @@ -6,18 +6,20 @@ Then /^(.*) should get (.+) '(.+)' emails?$/i do |to, amount, subject| address = email_address(to) attempt_to do - emails = emails_to(address, subject) - - unless emails.length == (str_to_num(amount)) - email_log = [] - ActionMailer::Base.deliveries.each do |mail| - email_log << "\t#{mail.to.join(', ')}: #{mail.subject}" + attempt_to do + emails = emails_to(address, subject) + + unless emails.length == (str_to_num(amount)) + email_log = [] + ActionMailer::Base.deliveries.each do |mail| + email_log << "\t#{mail.to.join(', ')}: #{mail.subject}" + end + total_emails = ActionMailer::Base.deliveries.length + fail "Failed to find #{amount} email#{amount == 1 ? '' : 's'} to #{address} with #{subject} in the subject amoung #{total_emails} total email#{total_emails == 1 ? '' : 's'}:\n#{email_log.join("\n")}" end - total_emails = ActionMailer::Base.deliveries.length - fail "Failed to find #{amount} email#{amount == 1 ? '' : 's'} to #{address} with #{subject} in the subject amoung #{total_emails} total email#{total_emails == 1 ? '' : 's'}:\n#{email_log.join("\n")}" - end - TestState.last_email = emails.first + TestState.last_email = emails.first + end end end diff --git a/features/step_definitions/interface_steps.rb b/features/step_definitions/interface_steps.rb index 395bb74..1dbe7a4 100644 --- a/features/step_definitions/interface_steps.rb +++ b/features/step_definitions/interface_steps.rb @@ -35,7 +35,6 @@ Then /^(?:I )?click (?:on )?(?:the )?(a )?'(.+?)'( button| link)?(?: beside '(.+ end element.click rescue Exception => e - puts text raise e end sleep(1) # let any aimations or page loads to complete diff --git a/tmp/locales/.gitkeep b/tmp/locales/.gitkeep deleted file mode 100644 index e69de29..0000000