Skip to content

Commit

Permalink
Explain new scoping behaviour in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Jul 10, 2010
1 parent 322ecd3 commit 970fd49
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions README.rdoc
Expand Up @@ -183,47 +183,6 @@ with the various form elements:
attach_file('Image', '/path/to/image.jpg')
select('Option', :from => 'Select Box')

=== Scoping

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
this purpose you can use the generic <tt>within</tt> method. Optionally you can
specify which kind of selector (CSS or XPath to use).

within("//li[@id='employee']") do
fill_in 'Name', :with => 'Jimmy'
end

within(:css, "li#employee") do
fill_in 'Name', :with => 'Jimmy'
end

You can choose which kind of selector Capybara uses by default, by setting
<tt>Capybara.default_selector</tt>.

There are special methods for restricting the scope to a specific fieldset,
identified by either an id or the text of the fieldet's legend tag, and to a
specific table, identified by either id or text of the table's caption tag.

within_fieldset('Employee') do
fill_in 'Name', :with => 'Jimmy'
end

within_table('Employee') do
fill_in 'Name', :with => 'Jimmy'
end

You can also specify a scope to be used for future searches with the <tt>scope_to</tt>.
It returns a handle to the session scoped to the provided selector.

scope = page.scope_to("//div[@id='foo']")
scope.has_xpath("//a[@class='bar']")

You can also chain scopes by calling <tt>scope_to</tt> on an existing scope.

more_scope = scope.scope_to("//p")
more_scope.has_xpath("//a[@class='baz']")

=== Querying

Capybara has a rich set of options for querying the page for the existence of
Expand All @@ -244,6 +203,8 @@ Note that <tt>page.should have_no_xpath</tt> is preferred over
<tt>page.should_not have_xpath</tt>. Read the section on asynchronous JavaScript
for an explanation.

=== Finding

You can also find specific elements, in order to manipulate them:

find_field('First Name').value
Expand All @@ -259,6 +220,42 @@ will wait for an element to appear on the page, as explained in the AJAX section
does not appear it will raise an error. <tt>find</tt> will check if the element is there and
immediately return nil if it is not.

These elements all have all the Capybara DSL methods available, so you can restrict them
to specific parts of the page:

locate(:css, '#navigation').click_link('Home')
locate(:css, '#navigation').should have_button('Sign out')

=== Scoping

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
this purpose you can use the generic <tt>within</tt> method. Optionally you can
specify which kind of selector (CSS or XPath to use).

within("//li[@id='employee']") do
fill_in 'Name', :with => 'Jimmy'
end

within(:css, "li#employee") do
fill_in 'Name', :with => 'Jimmy'
end

You can choose which kind of selector Capybara uses by default, by setting
<tt>Capybara.default_selector</tt>.

There are special methods for restricting the scope to a specific fieldset,
identified by either an id or the text of the fieldet's legend tag, and to a
specific table, identified by either id or text of the table's caption tag.

within_fieldset('Employee') do
fill_in 'Name', :with => 'Jimmy'
end

within_table('Employee') do
fill_in 'Name', :with => 'Jimmy'
end

=== Scripting

In drivers which support it, you can easily execute JavaScript:
Expand Down

0 comments on commit 970fd49

Please sign in to comment.