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
|
== Using Capybara with Cucumber
|
||||||
|
|
||||||
Capybara is built to work nicely with Cucumber. The API is very similar to
|
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
|
Webrat, so if you know Webrat you should feel right at home. Support for
|
||||||
references to Webrat from your <tt>env.rb</tt>, if you're using Rails, make sure to set
|
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
|
And everything should be set up and ready to go.
|
||||||
env.rb. For Rails do this:
|
|
||||||
|
|
||||||
require 'capybara/rails'
|
If you want to use Capybara with Cucumber outside Rails (for example with Merb
|
||||||
require 'capybara/cucumber'
|
or Sinatra), you'll need require capybara and set the Rack app manually:
|
||||||
|
|
||||||
For other frameworks, you'll need to set the Rack app manually:
|
|
||||||
|
|
||||||
require 'capybara/cucumber'
|
require 'capybara/cucumber'
|
||||||
Capybara.app = MyRackApp
|
Capybara.app = MyRackApp
|
||||||
|
|
|
@ -57,31 +57,31 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_field(locator)
|
def text_field(locator)
|
||||||
add_field(locator) { |id| "//input[@type='text'][@id=#{id}]" }
|
add_field(locator, "//input[@type='text']")
|
||||||
end
|
end
|
||||||
|
|
||||||
def password_field(locator)
|
def password_field(locator)
|
||||||
add_field(locator) { |id| "//input[@type='password'][@id=#{id}]" }
|
add_field(locator, "//input[@type='password']")
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_area(locator)
|
def text_area(locator)
|
||||||
add_field(locator) { |id| "//textarea[@id=#{id}]" }
|
add_field(locator, "//textarea")
|
||||||
end
|
end
|
||||||
|
|
||||||
def radio_button(locator)
|
def radio_button(locator)
|
||||||
add_field(locator) { |id| "//input[@type='radio'][@id=#{id}]" }
|
add_field(locator, "//input[@type='radio']")
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkbox(locator)
|
def checkbox(locator)
|
||||||
add_field(locator) { |id| "//input[@type='checkbox'][@id=#{id}]" }
|
add_field(locator, "//input[@type='checkbox']")
|
||||||
end
|
end
|
||||||
|
|
||||||
def select(locator)
|
def select(locator)
|
||||||
add_field(locator) { |id| "//select[@id=#{id}]" }
|
add_field(locator, "//select")
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_field(locator)
|
def file_field(locator)
|
||||||
add_field(locator) { |id| "//input[@type='file'][@id=#{id}]" }
|
add_field(locator, "//input[@type='file']")
|
||||||
end
|
end
|
||||||
|
|
||||||
def scope(scope)
|
def scope(scope)
|
||||||
|
@ -102,10 +102,11 @@ module Capybara
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def add_field(locator)
|
def add_field(locator, field)
|
||||||
xpath = append(yield(s(locator)))
|
xpath = append("#{field}[@id=#{s(locator)}]")
|
||||||
xpath = xpath.append(yield("//label[contains(.,#{s(locator)})]/@for"))
|
xpath = xpath.append("#{field}[@id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
xpath.prepend(yield("//label[text()=#{s(locator)}]/@for"))
|
xpath = xpath.append("//label[contains(.,#{s(locator)})]#{field}")
|
||||||
|
xpath.prepend("#{field}[@id=//label[text()=#{s(locator)}]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sanitize a String for putting it into an xpath query
|
# 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')
|
@session.body.should include('Another World')
|
||||||
end
|
end
|
||||||
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 "all"
|
||||||
it_should_behave_like "attach_file"
|
it_should_behave_like "attach_file"
|
||||||
|
|
|
@ -17,6 +17,12 @@ module FillInSpec
|
||||||
extract_results(@session)['first_name'].should == 'Harry'
|
extract_results(@session)['first_name'].should == 'Harry'
|
||||||
end
|
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
|
it "should favour exact label matches over partial matches" do
|
||||||
@session.fill_in('Name', :with => 'Harry Jones')
|
@session.fill_in('Name', :with => 'Harry Jones')
|
||||||
@session.click_button('awesome')
|
@session.click_button('awesome')
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
<label for="form_name">Name</label>
|
<label for="form_name">Name</label>
|
||||||
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label>Street<br/>
|
||||||
|
<input type="text" name="form[street]" value="Sesame street 66"/>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="form_phone">Phone</label>
|
<label for="form_phone">Phone</label>
|
||||||
|
|
Loading…
Reference in a new issue