Browse Source

Implemented retries for failed scenarios

development
Godwin 8 years ago
parent
commit
f1c5aca087
  1. 64
      Rakefile
  2. 2
      features/schedule.feature
  3. 22
      features/step_definitions/emails.rb
  4. 1
      features/step_definitions/interface_steps.rb
  5. 0
      tmp/locales/.gitkeep

64
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

2
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

22
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

1
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

0
tmp/locales/.gitkeep

Loading…
Cancel
Save