raise an error if Capybara is stuck in time
This commit is contained in:
parent
b056efbfa5
commit
aaf2f44d2d
|
@ -4,6 +4,7 @@ require 'xpath'
|
||||||
module Capybara
|
module Capybara
|
||||||
class CapybaraError < StandardError; end
|
class CapybaraError < StandardError; end
|
||||||
class DriverNotFoundError < CapybaraError; end
|
class DriverNotFoundError < CapybaraError; end
|
||||||
|
class FrozenInTime < CapybaraError; end
|
||||||
class ElementNotFound < CapybaraError; end
|
class ElementNotFound < CapybaraError; end
|
||||||
class ExpectationNotMet < ElementNotFound; end
|
class ExpectationNotMet < ElementNotFound; end
|
||||||
class FileNotFound < CapybaraError; end
|
class FileNotFound < CapybaraError; end
|
||||||
|
|
|
@ -49,6 +49,7 @@ module Capybara
|
||||||
raise e unless (driver.respond_to?(:invalid_element_errors) and driver.invalid_element_errors.include?(e.class)) or e.is_a?(Capybara::ElementNotFound)
|
raise e unless (driver.respond_to?(:invalid_element_errors) and driver.invalid_element_errors.include?(e.class)) or e.is_a?(Capybara::ElementNotFound)
|
||||||
raise e if (Time.now - start_time) >= seconds
|
raise e if (Time.now - start_time) >= seconds
|
||||||
sleep(0.05)
|
sleep(0.05)
|
||||||
|
raise Capybara::FrozenInTime, "time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead" if Time.now == start_time
|
||||||
reload if Capybara.automatic_reload
|
reload if Capybara.automatic_reload
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,6 +123,15 @@ shared_examples_for "session with javascript support" do
|
||||||
@session.click_link('Click me')
|
@session.click_link('Click me')
|
||||||
@session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
|
@session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with frozen time" do
|
||||||
|
it "raises an error suggesting that Capybara is stuck in time" do
|
||||||
|
@session.visit('/with_js')
|
||||||
|
now = Time.now
|
||||||
|
Time.stub(:now).and_return(now)
|
||||||
|
expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#wait_until' do
|
describe '#wait_until' do
|
||||||
|
|
Loading…
Reference in New Issue