VERSION | = | '1.1.1' |
current_driver | -> | mode |
reset_sessions! | -> | reset! |
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] |
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
when using capybara/dsl, the following options are also available:
The current Capybara::Session base on what is set as Capybara.app and Capybara.current_driver
@return [Capybara::Session] The currently used session
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.
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
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