mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge branch 'master' of git://github.com/jnicklas/capybara
Conflicts: spec/session_spec.rb
This commit is contained in:
commit
aefdbd8c34
5 changed files with 30 additions and 28 deletions
15
README.rdoc
15
README.rdoc
|
@ -26,18 +26,15 @@ Capybara is hosted on Gemcutter, install it with:
|
|||
== Using Capybara with Cucumber
|
||||
|
||||
Capybara is built to work nicely with Cucumber. The API is very similar to
|
||||
Webrat, so if you know Webrat you should feel right at home. Remove any
|
||||
references to Webrat from your <tt>env.rb</tt>, if you're using Rails, make sure to set
|
||||
Webrat, so if you know Webrat you should feel right at home. Support for
|
||||
Capybara is built into cucumber-rails 0.2. In your Rails app, just run:
|
||||
|
||||
Cucumber::Rails::World.use_transactional_fixtures = false
|
||||
script/generate cucumber --capybara
|
||||
|
||||
Capybara uses DatabaseCleaner to truncate the database. Require Capybara in your
|
||||
env.rb. For Rails do this:
|
||||
And everything should be set up and ready to go.
|
||||
|
||||
require 'capybara/rails'
|
||||
require 'capybara/cucumber'
|
||||
|
||||
For other frameworks, you'll need to set the Rack app manually:
|
||||
If you want to use Capybara with Cucumber outside Rails (for example with Merb
|
||||
or Sinatra), you'll need require capybara and set the Rack app manually:
|
||||
|
||||
require 'capybara/cucumber'
|
||||
Capybara.app = MyRackApp
|
||||
|
|
|
@ -57,31 +57,31 @@ module Capybara
|
|||
end
|
||||
|
||||
def text_field(locator)
|
||||
add_field(locator) { |id| "//input[@type='text'][@id=#{id}]" }
|
||||
add_field(locator, "//input[@type='text']")
|
||||
end
|
||||
|
||||
def password_field(locator)
|
||||
add_field(locator) { |id| "//input[@type='password'][@id=#{id}]" }
|
||||
add_field(locator, "//input[@type='password']")
|
||||
end
|
||||
|
||||
def text_area(locator)
|
||||
add_field(locator) { |id| "//textarea[@id=#{id}]" }
|
||||
add_field(locator, "//textarea")
|
||||
end
|
||||
|
||||
def radio_button(locator)
|
||||
add_field(locator) { |id| "//input[@type='radio'][@id=#{id}]" }
|
||||
add_field(locator, "//input[@type='radio']")
|
||||
end
|
||||
|
||||
def checkbox(locator)
|
||||
add_field(locator) { |id| "//input[@type='checkbox'][@id=#{id}]" }
|
||||
add_field(locator, "//input[@type='checkbox']")
|
||||
end
|
||||
|
||||
def select(locator)
|
||||
add_field(locator) { |id| "//select[@id=#{id}]" }
|
||||
add_field(locator, "//select")
|
||||
end
|
||||
|
||||
def file_field(locator)
|
||||
add_field(locator) { |id| "//input[@type='file'][@id=#{id}]" }
|
||||
add_field(locator, "//input[@type='file']")
|
||||
end
|
||||
|
||||
def scope(scope)
|
||||
|
@ -102,10 +102,11 @@ module Capybara
|
|||
|
||||
protected
|
||||
|
||||
def add_field(locator)
|
||||
xpath = append(yield(s(locator)))
|
||||
xpath = xpath.append(yield("//label[contains(.,#{s(locator)})]/@for"))
|
||||
xpath.prepend(yield("//label[text()=#{s(locator)}]/@for"))
|
||||
def add_field(locator, field)
|
||||
xpath = append("#{field}[@id=#{s(locator)}]")
|
||||
xpath = xpath.append("#{field}[@id=//label[contains(.,#{s(locator)})]/@for]")
|
||||
xpath = xpath.append("//label[contains(.,#{s(locator)})]#{field}")
|
||||
xpath.prepend("#{field}[@id=//label[text()=#{s(locator)}]/@for]")
|
||||
end
|
||||
|
||||
# Sanitize a String for putting it into an xpath query
|
||||
|
|
|
@ -20,14 +20,6 @@ shared_examples_for "session" do
|
|||
@session.body.should include('Another World')
|
||||
end
|
||||
end
|
||||
|
||||
#describe '#click_element' do
|
||||
# it "should click on a element" do
|
||||
# @session.visit('/with_html')
|
||||
# @session.click_element('fool_to_cry')
|
||||
# @session.body.should include('<div id="fool_to_cry">and I go see her sometimes<br />And we make love, so fine<br />I put my head on her shoulder<br /></div>')
|
||||
# end
|
||||
#end
|
||||
|
||||
it_should_behave_like "all"
|
||||
it_should_behave_like "attach_file"
|
||||
|
|
|
@ -17,6 +17,12 @@ module FillInSpec
|
|||
extract_results(@session)['first_name'].should == 'Harry'
|
||||
end
|
||||
|
||||
it "should fill in a text field by label without for" do
|
||||
@session.fill_in('Street', :with => 'Avenue Q')
|
||||
@session.click_button('awesome')
|
||||
extract_results(@session)['street'].should == 'Avenue Q'
|
||||
end
|
||||
|
||||
it "should favour exact label matches over partial matches" do
|
||||
@session.fill_in('Name', :with => 'Harry Jones')
|
||||
@session.click_button('awesome')
|
||||
|
|
|
@ -17,6 +17,12 @@
|
|||
<label for="form_name">Name</label>
|
||||
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>Street<br/>
|
||||
<input type="text" name="form[street]" value="Sesame street 66"/>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="form_phone">Phone</label>
|
||||
|
|
Loading…
Reference in a new issue