Class: Capybara::Node::Base

Overview

A Base represents either an element on a page through the
subclass Element or a document through
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
Finders, Actions and
Matchers respectively.

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

This method is Capybara's primary defence against asynchronicity
problems. It works by attempting to run a given block of code until it
succeeds. The exact behaviour of this method depends on a number of
factors. Basically there are certain exceptions which, when raised from the
block, instead of bubbling up, are caught, and the block is re-run.

Certain drivers, such as RackTest, have no support for asynchronous
processes, these drivers run the block, and any error raised bubbles up
immediately. This allows faster turn around in the case where an
expectation fails.

Only exceptions that are ElementNotFound or any subclass
thereof cause the block to be rerun. Drivers may specify additional
exceptions which also cause reruns. This usually occurs when a node is
manipulated which no longer exists on the page. For example, the Selenium
driver specifies `Selenium::WebDriver::Error::ObsoleteElementError`.

As long as any of these exceptions are thrown, the block is re-run, until a
certain amount of time passes. The amount of time defaults to
Capybara.default_max_wait_time and can be overridden through the
`seconds` argument. This time is compared with the system time to see how
much time has passed. On rubies/platforms which don't support access to
a monotonic process clock if the return value of `Time.now` is stubbed out,
Capybara will raise `Capybara::FrozenInTime`.

# File 'lib/capybara/node/base.rb', line 77defsynchronize(seconds=session_options.default_max_wait_time,errors:nil)ifsession.synchronizedyieldelsesession.synchronized=truestart_time=Capybara::Helpers.monotonic_timebeginyieldrescue=>esession.raise_server_error!raiseeunlessdriver.wait?&&catch_error?(e,errors)raiseeif(Capybara::Helpers.monotonic_time-start_time)>=secondssleep(0.05)raiseCapybara::FrozenInTime,"time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead"ifCapybara::Helpers.monotonic_time==start_timereloadifsession_options.automatic_reloadretryensuresession.synchronized=falseendendend