Browse Source

Implemented retries for failed scenarios

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

62
Rakefile

@ -89,61 +89,35 @@ task "cucumber:debug" do
ENV['TEST_DEBUG'] = nil ENV['TEST_DEBUG'] = nil
end end
# Cucumber::Rake::Task.new(:cucumber) do |t|
# t.cucumber_opts = "features --format pretty"
# end
namespace :cucumber do namespace :cucumber do
directory 'tmp'
@rerun_file = 'tmp/rerun.txt'
Cucumber::Rake::Task.new(:all) do |task| FAILING_CUCUMBER_SCENARIOS_FILENAME = 'log/rerun.txt'
task.cucumber_opts = "features --format pretty --format rerun --out tmp/rerun.txt"
end
desc 'Run cucumber features' Cucumber::Rake::Task.new(:start) do |task|
task run: :tmp do task.cucumber_opts = "features --format pretty -f rerun --out #{FAILING_CUCUMBER_SCENARIOS_FILENAME}"
retry_on_failure do
run_features
end
clean_up
exit @exit_status
end end
def retry_on_failure Cucumber::Rake::Task.new(:retry) do |task|
rm_rf @rerun_file task.cucumber_opts = "@#{FAILING_CUCUMBER_SCENARIOS_FILENAME}"
@retries = 0
begin
@exit_status = 0
yield
rescue SystemExit => e
@exit_status = e.status
if retry?(exception: e)
@retries += 1
retry
end
end
end end
def run_features task :run do
if File.exists? @rerun_file exception = nil
Cucumber::Rake::Task::ForkedCucumberRunner.new(['lib'], Cucumber::BINARY, [ begin
'features', result = Rake::Task['cucumber:start'].execute
'--format', 'pretty', rescue Exception => e
'@tmp/rerun.txt', begin
'--format', 'rerun', puts "\nRetrying failed scenarios...\n"
'--out', 'tmp/rerun.txt' Rake::Task['cucumber:retry'].execute
], true, []).run rescue Exception => e2
else exception = e2
Rake::Task['cucumber:all'].invoke
end end
end end
def retry?(exception: nil) if File.exists?("#{FAILING_CUCUMBER_SCENARIOS_FILENAME}")
@retries < 2 && !exception.success? File.delete("#{FAILING_CUCUMBER_SCENARIOS_FILENAME}")
end end
def clean_up raise exception unless exception.nil?
rm_rf @rerun_file.pathmap("%d")
end end
end end

2
features/schedule.feature

@ -57,7 +57,7 @@ Feature: Conference Schedule
When I click on 'Reaching New Immigrants' link When I click on 'Reaching New Immigrants' link
Then I should see 'The Shop' Then I should see 'The Shop'
And see '1027 Flatbush Ave' And see '1027 Flatbush Ave'
And see 'More info' And see 'Details'
And see 'Close' And see 'Close'
When I click on the 'Close' button When I click on the 'Close' button

2
features/step_definitions/emails.rb

@ -5,6 +5,7 @@ end
Then /^(.*) should get (.+) '(.+)' emails?$/i do |to, amount, subject| Then /^(.*) should get (.+) '(.+)' emails?$/i do |to, amount, subject|
address = email_address(to) address = email_address(to)
attempt_to do
attempt_to do attempt_to do
emails = emails_to(address, subject) emails = emails_to(address, subject)
@ -19,6 +20,7 @@ Then /^(.*) should get (.+) '(.+)' emails?$/i do |to, amount, subject|
TestState.last_email = emails.first TestState.last_email = emails.first
end end
end
end end
Then /^th(?:e|at) email should contain (.+)$/i do |value| Then /^th(?:e|at) email should contain (.+)$/i do |value|

1
features/step_definitions/interface_steps.rb

@ -35,7 +35,6 @@ Then /^(?:I )?click (?:on )?(?:the )?(a )?'(.+?)'( button| link)?(?: beside '(.+
end end
element.click element.click
rescue Exception => e rescue Exception => e
puts text
raise e raise e
end end
sleep(1) # let any aimations or page loads to complete sleep(1) # let any aimations or page loads to complete

0
tmp/locales/.gitkeep

Loading…
Cancel
Save