1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge branch 'jnicklas-master'

This commit is contained in:
Dennis Rogenius 2009-11-25 00:42:59 +01:00
commit f70d31ba61
11 changed files with 203 additions and 60 deletions

View file

@ -10,10 +10,18 @@ a DSL for interacting with a webapplication. It is agnostic about the driver
running your tests and currently comes bundled with rack-test, Culerity and
Selenium support built in.
== Disclaimer:
== Install:
Capybara is alpha level software, don't use it unless you're prepared to get
your hands dirty.
Capybara is hosted on Gemcutter, install it with:
sudo gem install capybara
== Development:
* Source hosted at {GitHub}[http://github.com/jnicklas/capybara].
* Please direct questions, discussions at the {mailing list}[http://groups.google.com/group/ruby-capybara].
* Report issues on {GitHub Issues}[http://github.com/jnicklas/capybara/issues]
* Pull requests are very welcome!
== Using Capybara with Cucumber
@ -86,6 +94,8 @@ Navigation:
Scoping:
within Takes a block which executes in the given scope
within_fieldset Execute the block in the fieldset given by id or legend
within_table Execute the block in the table given by id or caption
Interaction:
@ -143,18 +153,10 @@ For ultimate control, you can instantiate and use a session manually.
end
session.click_link 'Sign in'
== Install:
Capybara is hosted on Gemcutter, install it with:
sudo gem install capybara
== Gotchas:
* Install JRuby and the 'celerity' gem, version 0.7.4 (0.7.5 has a bug with
password fields) under JRuby for Culerity support. Also you'll need to install
teh edge version of Culerity until a new gem release becomes available, since
0.2.3 does not work (at all!) with Capybara.
password fields) under JRuby for Culerity support.
* Everything is *case sensitive*. Capybara heavily relies on XPath, which
doesn't support case insensitive searches.

View file

@ -18,12 +18,17 @@ $hoe = Hoe.spec 'capybara' do
self.extra_deps = [
['nokogiri', '>= 1.3.3'],
['culerity', '>= 0.2.3'],
['culerity', '>= 0.2.4'],
['selenium-webdriver', '>= 0.0.3'],
['rack', '>= 1.0.0'],
['rack-test', '>= 0.5.2'],
['database_cleaner', '>= 0.2.3']
]
self.extra_dev_deps = [
['sinatra', '>= 0.9.4'],
['rspec', '>= 1.2.9']
]
end
require 'newgem/tasks'

View file

@ -1,7 +1,7 @@
require 'nokogiri'
module Capybara
VERSION = '0.1.1'
VERSION = '0.1.2'
class CapybaraError < StandardError; end
class DriverNotFoundError < CapybaraError; end

View file

@ -44,8 +44,9 @@ module Capybara
SESSION_METHODS = [
:visit, :body, :click_link, :click_button, :fill_in, :choose, :has_xpath?, :has_css?,
:check, :uncheck, :attach_file, :select, :has_content?, :within, :save_and_open_page,
:find_field, :find_link, :find_button, :field_labeled
:check, :uncheck, :attach_file, :select, :has_content?, :within, :within_fieldset,
:within_table, :save_and_open_page, :find_field, :find_link, :find_button,
:field_labeled
]
SESSION_METHODS.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__+1

View file

@ -100,6 +100,18 @@ class Capybara::Session
scopes.pop
end
def within_fieldset(locator)
within "//fieldset[@id='#{locator}' or contains(legend,'#{locator}')]" do
yield
end
end
def within_table(locator)
within "//table[@id='#{locator}' or contains(caption,'#{locator}')]" do
yield
end
end
def save_and_open_page
require 'capybara/save_and_open_page'
Capybara::SaveAndOpenPage.save_and_open_page(body)

View file

@ -1,10 +1,10 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__))
describe Capybara::Driver::FireWatir do
before do
@driver = Capybara::Driver::FireWatir.new(TestApp)
end
# it_should_behave_like "driver"
# it_should_behave_like "driver with javascript support"
end
# describe Capybara::Driver::FireWatir do
# before do
# @driver = Capybara::Driver::FireWatir.new(TestApp)
# end
#
# it_should_behave_like "driver"
# it_should_behave_like "driver with javascript support"
# end

View file

@ -1,10 +1,10 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__))
describe Capybara::Driver::SafariWatir do
before do
@driver = Capybara::Driver::SafariWatir.new(TestApp)
end
# it_should_behave_like "driver"
# it_should_behave_like "driver with javascript support"
end
# describe Capybara::Driver::SafariWatir do
# before do
# @driver = Capybara::Driver::SafariWatir.new(TestApp)
# end
#
# it_should_behave_like "driver"
# it_should_behave_like "driver with javascript support"
# end

View file

@ -594,6 +594,50 @@ shared_examples_for "session" do
end
end
end
describe '#within_fieldset' do
before do
@session.visit('/fieldsets')
end
it "should restrict scope to a fieldset given by id" do
@session.within_fieldset("villain_fieldset") do
@session.fill_in("Name", :with => 'Goldfinger')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Goldfinger'
end
it "should restrict scope to a fieldset given by legend" do
@session.within_fieldset("Villain") do
@session.fill_in("Name", :with => 'Goldfinger')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Goldfinger'
end
end
describe '#within_table' do
before do
@session.visit('/tables')
end
it "should restrict scope to a fieldset given by id" do
@session.within_table("girl_table") do
@session.fill_in("Name", :with => 'Christmas')
@session.click_button("Create")
end
extract_results(@session)['girl_name'].should == 'Christmas'
end
it "should restrict scope to a fieldset given by legend" do
@session.within_table("Villain") do
@session.fill_in("Name", :with => 'Quantum')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Quantum'
end
end
end
describe Capybara::Session do

View file

@ -12,31 +12,7 @@ class TestApp < Sinatra::Base
get '/foo' do
'Another World'
end
get '/with_html' do
erb :with_html
end
get '/with_js' do
erb :with_js
end
get '/with_simple_html' do
erb :with_simple_html
end
get '/with_scope' do
erb :with_scope
end
get '/form' do
erb :form
end
post '/redirect' do
redirect '/redirect_again'
end
get '/redirect' do
redirect '/redirect_again'
end
@ -48,12 +24,24 @@ class TestApp < Sinatra::Base
get '/landed' do
"You landed"
end
post '/form' do
get '/form/get' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
get '/form/get' do
get '/favicon.ico' do
nil
end
get '/:view' do |view|
erb view.to_sym
end
post '/redirect' do
redirect '/redirect_again'
end
post '/form' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end

29
spec/views/fieldsets.erb Normal file
View file

@ -0,0 +1,29 @@
<form action="/form" method="post">
<fieldset id="agent_fieldset">
<legend>Agent</legend>
<p>
<label for="form_agent_name">Name</label>
<input type="text" name="form[agent_name]" value="James" id="form_agent_name"/>
</p>
<p>
<input type="submit" value="Create"/>
</p>
</fieldset>
</form>
<form action="/form" method="post">
<fieldset id="villain_fieldset">
<legend>Villain</legend>
<p>
<label for="form_villain_name">Name</label>
<input type="text" name="form[villain_name]" value="Ernst" id="form_villain_name"/>
</p>
<p>
<input type="submit" value="Create"/>
</p>
</fieldset>
</form>

62
spec/views/tables.erb Normal file
View file

@ -0,0 +1,62 @@
<form action="/form" method="post">
<table id="agent_table">
<caption>Agent</caption>
<tr>
<td>
<label for="form_agent_name">Name</label>
</td>
<td>
<input type="text" name="form[agent_name]" value="James" id="form_agent_name"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Create"/>
</td>
</tr>
</table>
</form>
<form action="/form" method="post">
<table id="girl_table">
<caption>Girl</caption>
<tr>
<td>
<label for="form_girl_name">Name</label>
</td>
<td>
<input type="text" name="form[girl_name]" value="Vesper" id="form_girl_name"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Create"/>
</td>
</tr>
</table>
</form>
<form action="/form" method="post">
<table id="villain_table">
<caption>Villain</caption>
<tr>
<td>
<label for="form_villain_name">Name</label>
</td>
<td>
<input type="text" name="form[villain_name]" value="Ernst" id="form_villain_name"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Create"/>
</td>
</tr>
</table>
</form>