mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added 'choose' for radio buttons
This commit is contained in:
parent
c6a689bf6d
commit
147b81d6b3
4 changed files with 33 additions and 7 deletions
|
@ -13,8 +13,11 @@ class Webcat::Driver::RackTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(value)
|
def set(value)
|
||||||
if tag_name == 'input'
|
if tag_name == 'input' and %w(text password).include?(type)
|
||||||
node['value'] = value.to_s
|
node['value'] = value.to_s
|
||||||
|
elsif tag_name == 'input' and type == 'radio'
|
||||||
|
session.html.xpath("//input[@name='#{self[:name]}']").each { |node| node.remove_attribute("checked") }
|
||||||
|
node['checked'] = 'checked'
|
||||||
elsif tag_name == "textarea"
|
elsif tag_name == "textarea"
|
||||||
node.content = value.to_s
|
node.content = value.to_s
|
||||||
end
|
end
|
||||||
|
@ -23,7 +26,7 @@ class Webcat::Driver::RackTest
|
||||||
def click
|
def click
|
||||||
if tag_name == 'a'
|
if tag_name == 'a'
|
||||||
session.visit(self[:href])
|
session.visit(self[:href])
|
||||||
elsif tag_name == 'input' and self[:type] == 'submit'
|
elsif tag_name == 'input' and type == 'submit'
|
||||||
Form.new(session, form).submit(self)
|
Form.new(session, form).submit(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -33,6 +36,10 @@ class Webcat::Driver::RackTest
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def type
|
||||||
|
self[:type]
|
||||||
|
end
|
||||||
|
|
||||||
def form
|
def form
|
||||||
node.ancestors('form').first
|
node.ancestors('form').first
|
||||||
|
|
|
@ -32,6 +32,10 @@ class Webcat::Session
|
||||||
def fill_in(locator, options={})
|
def fill_in(locator, options={})
|
||||||
find_field(locator, :text_field, :text_area, :password_field).set(options[:with])
|
find_field(locator, :text_field, :text_area, :password_field).set(options[:with])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def choose(locator)
|
||||||
|
find_field(locator, :radio).set(true)
|
||||||
|
end
|
||||||
|
|
||||||
def body
|
def body
|
||||||
driver.body
|
driver.body
|
||||||
|
@ -54,7 +58,8 @@ private
|
||||||
FIELDS_PATHS = {
|
FIELDS_PATHS = {
|
||||||
:text_field => proc { |id| "//input[@type='text'][@id='#{id}']" },
|
:text_field => proc { |id| "//input[@type='text'][@id='#{id}']" },
|
||||||
:text_area => proc { |id| "//textarea[@id='#{id}']" },
|
:text_area => proc { |id| "//textarea[@id='#{id}']" },
|
||||||
:password_field => proc { |id| "//input[@type='password'][@id='#{id}']" }
|
:password_field => proc { |id| "//input[@type='password'][@id='#{id}']" },
|
||||||
|
:radio => proc { |id| "//input[@type='radio'][@id='#{id}']" }
|
||||||
}
|
}
|
||||||
|
|
||||||
def find_field_by_id(locator, *kinds)
|
def find_field_by_id(locator, *kinds)
|
||||||
|
|
|
@ -171,7 +171,21 @@ shared_examples_for "session" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#choose" do
|
describe "#choose" do
|
||||||
|
before do
|
||||||
|
@session.visit('/form')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should choose a radio button by id" do
|
||||||
|
@session.choose("gender_male")
|
||||||
|
@session.click_button('awesome')
|
||||||
|
YAML.load(@session.body)['gender'].should == 'male'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should choose a radio button by label" do
|
||||||
|
@session.choose("Both")
|
||||||
|
@session.click_button('awesome')
|
||||||
|
YAML.load(@session.body)['gender'].should == 'both'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#set_hidden_field" do
|
describe "#set_hidden_field" do
|
||||||
|
|
|
@ -55,11 +55,11 @@
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<input type="radio" name=form[gender] value="male" id="gender_male"/>
|
<input type="radio" name="form[gender]" value="male" id="gender_male"/>
|
||||||
<label for="gender_male">Male</label>
|
<label for="gender_male">Male</label>
|
||||||
<input type="radio" name=form[gender] value="female" id="gender_female" checked="checked"/>
|
<input type="radio" name="form[gender]" value="female" id="gender_female" checked="checked"/>
|
||||||
<label for="gender_female">Female</label>
|
<label for="gender_female">Female</label>
|
||||||
<input type="radio" name=form[gender] value="both" id="gender_both"/>
|
<input type="radio" name="form[gender]" value="both" id="gender_both"/>
|
||||||
<label for="gender_both">Both</label>
|
<label for="gender_both">Both</label>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue