merge
This commit is contained in:
commit
e247347160
@ -1,3 +1,5 @@
|
||||
require 'sourcify'
|
||||
|
||||
MAX_TIMES = 20
|
||||
WAIT_TIME = 0.1
|
||||
|
||||
@ -6,6 +8,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
|
||||
@ -19,12 +24,35 @@ def _wait_for_not_exceptions
|
||||
exceptions
|
||||
end
|
||||
|
||||
def wait_for(times = MAX_TIMES)
|
||||
def _wait_for_not_continue_exceptions
|
||||
exceptions = []
|
||||
if defined?(Selenium::WebDriver::Error::StaleElementReferenceError)
|
||||
exceptions << Selenium::WebDriver::Error::StaleElementReferenceError
|
||||
end
|
||||
|
||||
exceptions
|
||||
end
|
||||
|
||||
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
|
||||
@ -36,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
|
||||
|
||||
@ -47,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
|
||||
@ -61,6 +91,6 @@ def wait_for_not(times = MAX_TIMES)
|
||||
end
|
||||
end
|
||||
|
||||
raise StandardError.new('Timed out')
|
||||
raise WaitingForElementFailure.new(block)
|
||||
end
|
||||
|
||||
|
12
lib/cuke-pack/tasks/make_default.rb
Normal file
12
lib/cuke-pack/tasks/make_default.rb
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user