Implemented retries for failed scenarios
This commit is contained in:
parent
71745f9deb
commit
f1c5aca087
64
Rakefile
64
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'
|
FAILING_CUCUMBER_SCENARIOS_FILENAME = 'log/rerun.txt'
|
||||||
|
|
||||||
Cucumber::Rake::Task.new(:all) do |task|
|
Cucumber::Rake::Task.new(:start) do |task|
|
||||||
task.cucumber_opts = "features --format pretty --format rerun --out tmp/rerun.txt"
|
task.cucumber_opts = "features --format pretty -f rerun --out #{FAILING_CUCUMBER_SCENARIOS_FILENAME}"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Run cucumber features'
|
Cucumber::Rake::Task.new(:retry) do |task|
|
||||||
task run: :tmp do
|
task.cucumber_opts = "@#{FAILING_CUCUMBER_SCENARIOS_FILENAME}"
|
||||||
retry_on_failure do
|
|
||||||
run_features
|
|
||||||
end
|
|
||||||
clean_up
|
|
||||||
exit @exit_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def retry_on_failure
|
task :run do
|
||||||
rm_rf @rerun_file
|
exception = nil
|
||||||
@retries = 0
|
|
||||||
begin
|
begin
|
||||||
@exit_status = 0
|
result = Rake::Task['cucumber:start'].execute
|
||||||
yield
|
rescue Exception => e
|
||||||
rescue SystemExit => e
|
begin
|
||||||
@exit_status = e.status
|
puts "\nRetrying failed scenarios...\n"
|
||||||
if retry?(exception: e)
|
Rake::Task['cucumber:retry'].execute
|
||||||
@retries += 1
|
rescue Exception => e2
|
||||||
retry
|
exception = e2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def run_features
|
if File.exists?("#{FAILING_CUCUMBER_SCENARIOS_FILENAME}")
|
||||||
if File.exists? @rerun_file
|
File.delete("#{FAILING_CUCUMBER_SCENARIOS_FILENAME}")
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def retry?(exception: nil)
|
raise exception unless exception.nil?
|
||||||
@retries < 2 && !exception.success?
|
|
||||||
end
|
|
||||||
|
|
||||||
def clean_up
|
|
||||||
rm_rf @rerun_file.pathmap("%d")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
|
@ -6,18 +6,20 @@ Then /^(.*) should get (.+) '(.+)' emails?$/i do |to, amount, subject|
|
|||||||
address = email_address(to)
|
address = email_address(to)
|
||||||
|
|
||||||
attempt_to do
|
attempt_to do
|
||||||
emails = emails_to(address, subject)
|
attempt_to do
|
||||||
|
emails = emails_to(address, subject)
|
||||||
|
|
||||||
unless emails.length == (str_to_num(amount))
|
unless emails.length == (str_to_num(amount))
|
||||||
email_log = []
|
email_log = []
|
||||||
ActionMailer::Base.deliveries.each do |mail|
|
ActionMailer::Base.deliveries.each do |mail|
|
||||||
email_log << "\t#{mail.to.join(', ')}: #{mail.subject}"
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user