From 899a4cb2af58afb5484f52e57d9e749aba10bacc Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 28 Aug 2012 10:01:53 -0400 Subject: [PATCH 1/3] wait_for handles disappearing elements better --- lib/cuke-pack/support/wait_for.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/cuke-pack/support/wait_for.rb b/lib/cuke-pack/support/wait_for.rb index 9de85de..fd83bed 100644 --- a/lib/cuke-pack/support/wait_for.rb +++ b/lib/cuke-pack/support/wait_for.rb @@ -6,6 +6,9 @@ def _wait_for_exceptions if defined?(Capybara::Driver::Webkit::Node::ElementNotDisplayedError) exceptions << Capybara::Driver::Webkit::Node::ElementNotDisplayedError end + if defined?(Selenium::WebDriver::Error::StaleElementReferenceError) + exceptions << Selenium::WebDriver::Error::StaleElementReferenceError + end exceptions end @@ -15,6 +18,9 @@ def _wait_for_not_exceptions if defined?(Capybara::Driver::Webkit::NodeNotAttachedError) exceptions << Capybara::Driver::Webkit::NodeNotAttachedError end + if defined?(Selenium::WebDriver::Error::StaleElementReferenceError) + exceptions << Selenium::WebDriver::Error::StaleElementReferenceError + end exceptions end From 036008f8c680c4893491d6e4e97c21f2aa2d2f5a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 28 Aug 2012 15:46:42 -0400 Subject: [PATCH 2/3] even better wait_for support --- cuke-pack.gemspec | 1 + lib/cuke-pack/support/wait_for.rb | 36 +++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cuke-pack.gemspec b/cuke-pack.gemspec index 9375896..eeac6fc 100644 --- a/cuke-pack.gemspec +++ b/cuke-pack.gemspec @@ -19,5 +19,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'cucumber-step_writer' gem.add_dependency 'thor' gem.add_dependency 'flay' + gem.add_dependency 'sourcify' end diff --git a/lib/cuke-pack/support/wait_for.rb b/lib/cuke-pack/support/wait_for.rb index fd83bed..4f056b0 100644 --- a/lib/cuke-pack/support/wait_for.rb +++ b/lib/cuke-pack/support/wait_for.rb @@ -1,3 +1,5 @@ +require 'sourcify' + MAX_TIMES = 20 WAIT_TIME = 0.1 @@ -18,6 +20,12 @@ def _wait_for_not_exceptions if defined?(Capybara::Driver::Webkit::NodeNotAttachedError) exceptions << Capybara::Driver::Webkit::NodeNotAttachedError end + + exceptions +end + +def _wait_for_not_continue_exceptions + exceptions = [] if defined?(Selenium::WebDriver::Error::StaleElementReferenceError) exceptions << Selenium::WebDriver::Error::StaleElementReferenceError end @@ -25,12 +33,26 @@ def _wait_for_not_exceptions exceptions end -def wait_for(times = MAX_TIMES) +class WaitingForElementFailure < StandardError + def initialize(code) + @code = code + end + + def message + @code.to_source(:strip_enclosure => true) + end + + def backtrace + [ @code.source_location.join(":") ] + end +end + +def wait_for(times = MAX_TIMES, &block) 1.upto(times) do ok = false begin - ok = yield + ok = block.() rescue *_wait_for_exceptions ok = false end @@ -42,10 +64,10 @@ def wait_for(times = MAX_TIMES) end end - raise StandardError.new("Failed") + raise WaitingForElementFailure.new(block) end -def wait_for_not(times = MAX_TIMES) +def wait_for_not(times = MAX_TIMES, &block) original_time = Capybara.default_wait_time Capybara.default_wait_time = 0 @@ -53,7 +75,9 @@ def wait_for_not(times = MAX_TIMES) ok = false begin - yield + block.() + rescue *_wait_for_not_continue_exceptions + ok = false rescue *_wait_for_not_exceptions ok = true end @@ -67,6 +91,6 @@ def wait_for_not(times = MAX_TIMES) end end - raise StandardError.new('Timed out') + raise WaitingForElementFailure.new(block) end From 648a808c82553729b7c28d1215353a0e578b9c69 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 14 Sep 2012 10:49:14 -0400 Subject: [PATCH 3/3] quick way to make cuke-pack integrate perfectly with penchant hooks --- lib/cuke-pack/tasks/make_default.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/cuke-pack/tasks/make_default.rb diff --git a/lib/cuke-pack/tasks/make_default.rb b/lib/cuke-pack/tasks/make_default.rb new file mode 100644 index 0000000..67c8d84 --- /dev/null +++ b/lib/cuke-pack/tasks/make_default.rb @@ -0,0 +1,12 @@ +require 'cuke-pack/tasks' + +task(:default).clear + +task :preflight_check do + task('cuke_pack:any_wip').invoke +end + +task :default do + task('cuke_pack:precommit').invoke +end +