Module Capybara
In: lib/capybara/rspec/features.rb
lib/capybara/rspec/matchers.rb
lib/capybara/version.rb
lib/capybara/util/save_and_open_page.rb
lib/capybara/util/timeout.rb
lib/capybara/dsl.rb
lib/capybara/node/element.rb
lib/capybara/node/finders.rb
lib/capybara/node/actions.rb
lib/capybara/node/simple.rb
lib/capybara/node/document.rb
lib/capybara/node/matchers.rb
lib/capybara/node/base.rb
lib/capybara/server.rb
lib/capybara/selector.rb
lib/capybara/session.rb
lib/capybara/driver/node.rb
lib/capybara.rb

Methods

Classes and Modules

Module Capybara::DSL
Module Capybara::Driver
Module Capybara::Features
Module Capybara::Node
Module Capybara::RSpecMatchers
Module Capybara::RackTest
Module Capybara::Selenium
Class Capybara::CapybaraError
Class Capybara::DriverNotFoundError
Class Capybara::ElementNotFound
Class Capybara::ExpectationNotMet
Class Capybara::FileNotFound
Class Capybara::FrozenInTime
Class Capybara::InfiniteRedirectError
Class Capybara::LocateHiddenElementError
Class Capybara::NotSupportedByDriverError
Class Capybara::Selector
Class Capybara::Server
Class Capybara::Session
Class Capybara::TimeoutError
Class Capybara::UnselectNotAllowed

Constants

VERSION = '1.1.1'

External Aliases

current_driver -> mode
reset_sessions! -> reset!

Attributes

app  [RW] 
app_host  [RW] 
asset_root  [RW] 
automatic_reload  [RW] 
current_driver  [W] 
default_driver  [W] 
default_host  [RW] 
default_selector  [RW] 
default_wait_time  [RW] 
ignore_hidden_elements  [RW] 
javascript_driver  [W] 
prefer_visible_elements  [RW] 
run_server  [RW] 
save_and_open_page_path  [RW] 
server_boot_timeout  [RW] 
server_port  [RW] 
session_name  [W] 

Public Class methods

Add a new selector to Capybara. Selectors can be used by various methods in Capybara to find certain elements on the page in a more convenient way. For example adding a selector to find certain table rows might look like this:

    Capybara.add_selector(:row) do
      xpath { |num| ".//tbody/tr[#{num}]" }
    end

This makes it possible to use this selector in a variety of ways:

    find(:row, 3)
    page.find('table#myTable').find(:row, 3).text
    page.find('table#myTable').has_selector?(:row, 3)
    within(:row, 3) { page.should have_content('$100.000') }

It might be convenient to specify that the selector is automatically chosen for certain values. This way you don‘t have to explicitly specify that you are looking for a row, or an id. Let‘s say we want Capybara to treat any Symbols sent into methods like find to be treated as though they were element ids. We could achieve this like so:

    Capybara.add_selector(:id) do
      xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
      match { |value| value.is_a?(Symbol) }
    end

Now we can retrieve elements by id like this:

    find(:post_123)

Note that this particular selector already ships with Capybara.

@param [Symbol] name The name of the selector to add @yield A block executed in the context of the new {Capybara::Selector}

Configure Capybara to suit your needs.

    Capybara.configure do |config|
      config.run_server = false
      config.app_host   = 'http://www.google.com'
    end

Configurable options

asset_root = String
Where static assets are located, used by save_and_open_page
app_host = String
The default host to use when giving a relative URL to visit
run_server = Boolean
Whether to start a Rack server for the given Rack app (Default: true)
default_selector = :css/:xpath
Methods which take a selector use the given type by default (Default: CSS)
default_wait_time = Integer
The number of seconds to wait for asynchronous processes to finish (Default: 2)
ignore_hidden_elements = Boolean
Whether to ignore hidden elements on the page (Default: false)
prefer_visible_elements = Boolean
Whether to prefer visible elements over hidden elements (Default: true)
automatic_reload = Boolean
Whether to automatically reload elements as Capybara is waiting (Default: true)
save_and_open_page_path = String
Where to put pages saved through save_and_open_page (Default: Dir.pwd)

DSL Options

when using capybara/dsl, the following options are also available:

default_driver = Symbol
The name of the driver to use by default. (Default: :rack_test)
javascript_driver = Symbol
The name of a driver to use for JavaScript enabled tests. (Default: :selenium)

@return [Symbol] The name of the driver currently in use

The current Capybara::Session base on what is set as Capybara.app and Capybara.current_driver

@return [Capybara::Session] The currently used session

@return [Symbol] The name of the driver to use by default

@return [Symbol] The name of the driver used when JavaScript is needed

Register a new driver for Capybara.

    Capybara.register_driver :rack_test do |app|
      Capybara::Driver::RackTest.new(app)
    end

@param [Symbol] name The name of the new driver @yield [app] This block takes a rack app and returns a Capybara driver @yieldparam [<Rack>] app The rack application that this driver runs agains. May be nil. @yieldreturn [Capybara::Driver::Base] A Capybara driver instance

Reset sessions, cleaning out the pool of sessions. This will remove any session information such as cookies.

Runs Capybara‘s default server for the given application and port under most circumstances you should not have to call this method manually.

@param [Rack Application] app The rack application to run @param [Fixnum] port The port to run the application on

Register a proc that Capybara will call to run the Rack application.

    Capybara.server do |app, port|
      require 'rack/handler/mongrel'
      Rack::Handler::Mongrel.run(app, :Port => port)
    end

By default, Capybara will try to run thin, falling back to webrick.

@yield [app, port] This block recieves a rack app and port and should run a Rack handler

The current session name.

@return [Symbol] The name of the currently used session.

Wraps the given string, which should contain an HTML document or fragment in a {Capybara::Node::Simple} which exposes all {Capybara::Node::Matchers} and {Capybara::Node::Finders}. This allows you to query any string containing HTML in the exact same way you would query the current document in a Capybara session. For example:

    node = Capybara.string <<-HTML
      <ul>
        <li id="home">Home</li>
        <li id="projects">Projects</li>
      </ul>
    HTML

    node.find('#projects').text # => 'Projects'
    node.has_selector?('li#home', :text => 'Home')
    node.has_selector?(:projects)
    node.find('ul').find('li').text # => 'Home'

@param [String] html An html fragment or document @return [Capybara::Node::Simple] A node which has Capybara‘s finders and matchers

Provides timeout similar to standard library Timeout, but avoids threads

Use the default driver as the current driver

Yield a block using a specific driver

Yield a block using a specific session name.

Yield a block using a specific wait time

Protected Class methods

[Validate]