mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Improve README
This commit is contained in:
parent
558e7b2d4d
commit
f5f444b969
1 changed files with 32 additions and 18 deletions
50
README.rdoc
50
README.rdoc
|
@ -11,8 +11,8 @@ tests and currently comes bundled with rack-test, Culerity, Celerity and Seleniu
|
||||||
support built in. env.js support is available as the
|
support built in. env.js support is available as the
|
||||||
{capybara-envjs gem}[http://github.com/smparkes/capybara-envjs].
|
{capybara-envjs gem}[http://github.com/smparkes/capybara-envjs].
|
||||||
|
|
||||||
Online documentation is availbable
|
A complete reference is available at
|
||||||
{at rdoc.info}[http://rdoc.info/projects/jnicklas/capybara].
|
{at rubydoc.info}[http://rubydoc.info/github/jnicklas/capybara/master].
|
||||||
|
|
||||||
== Install:
|
== Install:
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ you make.
|
||||||
|
|
||||||
Capybara uses bundler in development. To set up a development environment, simply do:
|
Capybara uses bundler in development. To set up a development environment, simply do:
|
||||||
|
|
||||||
|
git submodule update --init
|
||||||
gem install bundler --pre
|
gem install bundler --pre
|
||||||
bundle install
|
bundle install
|
||||||
|
|
||||||
|
@ -126,7 +127,7 @@ You'll need to roll your own for earlier versions of RSpec.
|
||||||
You can use the built-in Rails support to easily get Capybara running with
|
You can use the built-in Rails support to easily get Capybara running with
|
||||||
Rails:
|
Rails:
|
||||||
|
|
||||||
requires 'capybara/rails'
|
require 'capybara/rails'
|
||||||
|
|
||||||
== Using Capybara with Rack
|
== Using Capybara with Rack
|
||||||
|
|
||||||
|
@ -183,15 +184,22 @@ Ruby 1.8.7 at this time.
|
||||||
|
|
||||||
== The DSL
|
== The DSL
|
||||||
|
|
||||||
Capybara's DSL is inspired by Webrat. While backwards compatibility is retained
|
Capybara's DSL (domain-specific language) is inspired by Webrat. While
|
||||||
in a lot of cases, there are certain important differences.
|
backwards compatibility is retained in a lot of cases, there are certain
|
||||||
|
important differences. Unlike in Webrat, all searches in Capybara are *case
|
||||||
|
sensitive*. This is because Capybara heavily uses XPath, which doesn't support
|
||||||
|
case insensitivity.
|
||||||
|
|
||||||
Unlike in Webrat, all searches in Capybara are *case sensitive*. This is because
|
For a full reference of the DSL, check
|
||||||
Capybara heavily uses XPath, which doesn't support case insensitivity.
|
{Capybara::Session}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session]
|
||||||
|
and the modules defined in
|
||||||
|
{Capybara::Node}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node].
|
||||||
|
|
||||||
=== Navigating
|
=== Navigating
|
||||||
|
|
||||||
You can use the <tt>visit</tt> method to navigate to other pages:
|
You can use the
|
||||||
|
{<tt>visit</tt>}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#visit-instance_method]
|
||||||
|
method to navigate to other pages:
|
||||||
|
|
||||||
visit('/projects')
|
visit('/projects')
|
||||||
visit(post_comments_path(post))
|
visit(post_comments_path(post))
|
||||||
|
@ -199,7 +207,9 @@ You can use the <tt>visit</tt> method to navigate to other pages:
|
||||||
The visit method only takes a single parameter, the request method is *always*
|
The visit method only takes a single parameter, the request method is *always*
|
||||||
GET.
|
GET.
|
||||||
|
|
||||||
You can get the current path of the browsing session for test assertions:
|
You can get the {current
|
||||||
|
path}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#current_path-instance_method]
|
||||||
|
of the browsing session for test assertions:
|
||||||
|
|
||||||
current_path.should == post_comments_path(post)
|
current_path.should == post_comments_path(post)
|
||||||
|
|
||||||
|
@ -211,13 +221,14 @@ automatically follows any redirects, and submits forms associated with buttons.
|
||||||
click_link('id-of-link')
|
click_link('id-of-link')
|
||||||
click_link('Link Text')
|
click_link('Link Text')
|
||||||
click_button('Save')
|
click_button('Save')
|
||||||
click_link_or_button('Link Text')
|
click_on('Link Text') # clicks on either links or buttons
|
||||||
click_link_or_button('Button Value')
|
click_on('Button Value')
|
||||||
|
|
||||||
=== Interacting with forms
|
=== Interacting with forms
|
||||||
|
|
||||||
Forms are everywhere in webapps, there are a number of tools for interacting
|
Forms are everywhere in webapps, there are a number of tools for interacting
|
||||||
with the various form elements:
|
with the various form elements (see
|
||||||
|
{Capybara::Node::Actions}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions]):
|
||||||
|
|
||||||
fill_in('First Name', :with => 'John')
|
fill_in('First Name', :with => 'John')
|
||||||
fill_in('Password', :with => 'Seekrit')
|
fill_in('Password', :with => 'Seekrit')
|
||||||
|
@ -231,7 +242,8 @@ with the various form elements:
|
||||||
=== Querying
|
=== Querying
|
||||||
|
|
||||||
Capybara has a rich set of options for querying the page for the existence of
|
Capybara has a rich set of options for querying the page for the existence of
|
||||||
certain elements, and working with and manipulating those elements.
|
certain elements, and working with and manipulating those elements (see
|
||||||
|
{Capybara::Node::Matchers}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers]).
|
||||||
|
|
||||||
page.has_selector?('table tr')
|
page.has_selector?('table tr')
|
||||||
page.has_selector?(:xpath, '//table/tr')
|
page.has_selector?(:xpath, '//table/tr')
|
||||||
|
@ -258,7 +270,8 @@ for an explanation.
|
||||||
|
|
||||||
=== Finding
|
=== Finding
|
||||||
|
|
||||||
You can also find specific elements, in order to manipulate them:
|
You can also find specific elements, in order to manipulate them (see
|
||||||
|
{Capybara::Node::Finders}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders]):
|
||||||
|
|
||||||
find_field('First Name').value
|
find_field('First Name').value
|
||||||
find_link('Hello').visible?
|
find_link('Hello').visible?
|
||||||
|
@ -281,8 +294,9 @@ to specific parts of the page:
|
||||||
|
|
||||||
Capybara makes it possible to restrict certain actions, such as interacting with
|
Capybara makes it possible to restrict certain actions, such as interacting with
|
||||||
forms or clicking links and buttons, to within a specific area of the page. For
|
forms or clicking links and buttons, to within a specific area of the page. For
|
||||||
this purpose you can use the generic <tt>within</tt> method. Optionally you can
|
this purpose you can use the generic
|
||||||
specify which kind of selector to use.
|
{<tt>within</tt>}[http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#within-instance_method]
|
||||||
|
method. Optionally you can specify which kind of selector to use.
|
||||||
|
|
||||||
within("li#employee") do
|
within("li#employee") do
|
||||||
fill_in 'Name', :with => 'Jimmy'
|
fill_in 'Name', :with => 'Jimmy'
|
||||||
|
@ -417,8 +431,8 @@ For ultimate control, you can instantiate and use a session manually.
|
||||||
== XPath, CSS and selectors
|
== XPath, CSS and selectors
|
||||||
|
|
||||||
Capybara does not try to guess what kind of selector you are going to give it,
|
Capybara does not try to guess what kind of selector you are going to give it,
|
||||||
if you want to use XPath with your 'within' declarations for example, you'll need
|
and will always use CSS by default. If you want to use XPath, you'll need to
|
||||||
to do:
|
do:
|
||||||
|
|
||||||
within(:xpath, '//ul/li') { ... }
|
within(:xpath, '//ul/li') { ... }
|
||||||
find(:xpath, '//ul/li').text
|
find(:xpath, '//ul/li').text
|
||||||
|
|
Loading…
Reference in a new issue