Implemented retries for failed scenarios
This commit is contained in:
		
							parent
							
								
									71745f9deb
								
							
						
					
					
						commit
						f1c5aca087
					
				
							
								
								
									
										62
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										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"
 | 
					
 | 
				
			||||||
 | 
					  Cucumber::Rake::Task.new(:start) do |task|
 | 
				
			||||||
 | 
					    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
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  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
 | 
					 | 
				
			||||||
      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
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,6 +21,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|
 | 
				
			||||||
  TestState.last_email = ActionMailer::Base.deliveries.last
 | 
					  TestState.last_email = ActionMailer::Base.deliveries.last
 | 
				
			||||||
 | 
				
			|||||||
@ -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