Class: Capybara::Node::Base

### Home Classes Methods

### In Files

- lib/capybara/node/base.rb

### Parent

Object

### Methods

- ::new
- #catch_error?
- #driver
- #find_css
- #find_xpath
- #reload
- #synchronize

### Included Modules

- Capybara::Node::Finders
- Capybara::Node::Actions
- Capybara::Node::Matchers

### Files

- another_test_file.txt
- test_file.txt

### Class/Module Index

Quicksearch

- Capybara
- Capybara::Ambiguous
- Capybara::CapybaraError
- Capybara::DSL
- Capybara::Driver
- Capybara::Driver::Base
- Capybara::Driver::Node
- Capybara::DriverNotFoundError
- Capybara::ElementNotFound
- Capybara::ExpectationNotMet
- Capybara::Features
- Capybara::FileNotFound
- Capybara::FrozenInTime
- Capybara::Helpers
- Capybara::InfiniteRedirectError
- Capybara::ModalNotFound
- Capybara::Node
- Capybara::Node::Actions
- Capybara::Node::Base
- Capybara::Node::Document
- Capybara::Node::DocumentMatchers
- Capybara::Node::Element
- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::Simple
- Capybara::NotSupportedByDriverError
- Capybara::Queries
- Capybara::Queries::BaseQuery
- Capybara::Queries::TextQuery
- Capybara::Queries::TitleQuery
- Capybara::Query
- Capybara::RSpecMatchers
- Capybara::RSpecMatchers::BecomeClosed
- Capybara::RSpecMatchers::HaveSelector
- Capybara::RSpecMatchers::HaveText
- Capybara::RSpecMatchers::HaveTitle
- Capybara::RSpecMatchers::Matcher
- Capybara::RackTest
- Capybara::RackTest::Browser
- Capybara::RackTest::CSSHandlers
- Capybara::RackTest::Driver
- Capybara::RackTest::Form
- Capybara::RackTest::Form::NilUploadedFile
- Capybara::RackTest::Node
- Capybara::ReadOnlyElementError
- Capybara::Result
- Capybara::ScopeError
- Capybara::Selector
- Capybara::Selector::Filter
- Capybara::Selenium
- Capybara::Selenium::Driver
- Capybara::Selenium::Node
- Capybara::Server
- Capybara::Server::Middleware
- Capybara::Session
- Capybara::SpecHelper
- Capybara::UnselectNotAllowed
- Capybara::Window
- Capybara::WindowError
- TestApp
- TestApp::TestAppError
- Object

No matching classes.

# Capybara::Node::Base

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

### Attributes

base[R]
parent[R]
session[R]

### Public Class Methods

new(session, base) click to toggle source

    # File lib/capybara/node/base.rb, line 31
    def initialize(session, base)
      @session = session
      @base = base
    end

### Public Instance Methods

find_css(css) click to toggle source

@api private

    # File lib/capybara/node/base.rb, line 101
    def find_css(css)
      base.find_css(css)
    end

find_xpath(xpath) click to toggle source

@api private

    # File lib/capybara/node/base.rb, line 106
    def find_xpath(xpath)
      base.find_xpath(xpath)
    end

reload() click to toggle source

overridden in subclasses, e.g. Capybara::Node::Element

    # File lib/capybara/node/base.rb, line 37
    def reload
      self
    end

synchronize(seconds=Capybara.default_wait_time, options = {}) click to toggle source

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 {Capybara::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_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. If the return value of `Time.now` is stubbed out, Capybara will raise `Capybara::FrozenInTime`.

@param [Integer] seconds Number of seconds to retry this block @param options [Hash] @option options [Array<Exception>] :errors (driver.invalid_element_errors +

    [Capybara::ElementNotFound]) exception types that cause the block to be rerun

@return [Object] The result of the given block @raise [Capybara::FrozenInTime] If the return value of `Time.now` appears stuck

    # File lib/capybara/node/base.rb, line 76
    def synchronize(seconds=Capybara.default_wait_time, options = {})
      start_time = Time.now

      if session.synchronized
        yield
      else
        session.synchronized = true
        begin
          yield
        rescue => e
          session.raise_server_error!
          raise e unless driver.wait?
          raise e unless catch_error?(e, options[:errors])
          raise e if (Time.now - start_time) >= seconds
          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
          retry
        ensure
          session.synchronized = false
        end
      end
    end

### Protected Instance Methods

catch_error?(error, errors = nil) click to toggle source

    # File lib/capybara/node/base.rb, line 112
    def catch_error?(error, errors = nil)
      errors ||= (driver.invalid_element_errors + [Capybara::ElementNotFound])
      errors.any? do |type|
        error.is_a?(type)
      end
    end

driver() click to toggle source

    # File lib/capybara/node/base.rb, line 119
    def driver
      session.driver
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.