2010-11-21 08:37:36 -05:00
|
|
|
module Capybara
|
|
|
|
module Node
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# A {Capybara::Node::Base} represents either an element on a page through the subclass
|
|
|
|
# {Capybara::Node::Element} or a document through {Capybara::Node::Document}.
|
|
|
|
#
|
|
|
|
# Both types of Node share the same methods, used for interacting with the
|
|
|
|
# elements on the page. These methods are divided into three categories,
|
|
|
|
# finders, actions and matchers. These are found in the modules
|
|
|
|
# {Capybara::Node::Finders}, {Capybara::Node::Actions} and {Capybara::Node::Matchers}
|
|
|
|
# respectively.
|
|
|
|
#
|
|
|
|
# A {Capybara::Session} exposes all methods from {Capybara::Node::Document} directly:
|
|
|
|
#
|
|
|
|
# session = Capybara::Session.new(:rack_test, my_app)
|
|
|
|
# session.visit('/')
|
|
|
|
# session.fill_in('Foo', :with => 'Bar') # from Capybara::Node::Actions
|
|
|
|
# bar = session.find('#bar') # from Capybara::Node::Finders
|
|
|
|
# bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
|
|
|
|
# session.has_css?('#foobar') # from Capybara::Node::Matchers
|
|
|
|
#
|
|
|
|
class Base
|
2011-07-13 09:39:17 -04:00
|
|
|
attr_reader :session, :base, :parent
|
2010-11-21 08:37:36 -05:00
|
|
|
|
|
|
|
include Capybara::Node::Finders
|
|
|
|
include Capybara::Node::Actions
|
|
|
|
include Capybara::Node::Matchers
|
|
|
|
|
|
|
|
def initialize(session, base)
|
|
|
|
@session = session
|
|
|
|
@base = base
|
|
|
|
end
|
|
|
|
|
2011-07-13 09:39:17 -04:00
|
|
|
def reload
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2010-11-21 08:37:36 -05:00
|
|
|
protected
|
|
|
|
|
2011-08-12 07:52:12 -04:00
|
|
|
def wait_until(seconds=Capybara.default_wait_time)
|
|
|
|
start_time = Time.now
|
|
|
|
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
rescue => e
|
|
|
|
raise e unless wait?
|
|
|
|
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
|
|
|
|
sleep(0.05)
|
|
|
|
reload if Capybara.automatic_reload
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-21 08:37:36 -05:00
|
|
|
def wait?
|
|
|
|
driver.wait?
|
|
|
|
end
|
|
|
|
|
|
|
|
def driver
|
|
|
|
session.driver
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|