mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added within table method
This commit is contained in:
parent
5a89fafcdf
commit
334bca5d77
4 changed files with 91 additions and 1 deletions
|
@ -45,7 +45,8 @@ 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, :within_fieldset,
|
||||
:save_and_open_page, :find_field, :find_link, :find_button, :field_labeled
|
||||
: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
|
||||
|
|
|
@ -106,6 +106,12 @@ class Capybara::Session
|
|||
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)
|
||||
|
|
|
@ -615,7 +615,28 @@ shared_examples_for "session" do
|
|||
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
|
||||
|
||||
|
|
62
spec/views/tables.erb
Normal file
62
spec/views/tables.erb
Normal 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>
|
Loading…
Reference in a new issue