added basic html5 input types

This commit is contained in:
Louis T 2010-01-08 00:08:55 -05:00
parent 98e14103e1
commit bb887c5d1d
3 changed files with 64 additions and 20 deletions

View File

@ -38,7 +38,8 @@ module Capybara
end
def fillable_field(locator)
text_field(locator).password_field(locator).text_area(locator)
text_field(locator).password_field(locator).text_area(locator).email(locator)\
.url(locator).search(locator).tel(locator).color(locator)
end
def content(locator)
@ -62,32 +63,21 @@ module Capybara
xpath.append("//button[@id=#{s(locator)} or contains(@value,#{s(locator)}) or contains(.,#{s(locator)})]")
end
def text_field(locator)
add_field(locator, "//input[@type='text']")
end
def password_field(locator)
add_field(locator, "//input[@type='password']")
end
def text_area(locator)
add_field(locator, "//textarea")
end
def radio_button(locator)
add_field(locator, "//input[@type='radio']")
end
def checkbox(locator)
add_field(locator, "//input[@type='checkbox']")
end
def select(locator)
add_field(locator, "//select")
end
def file_field(locator)
add_field(locator, "//input[@type='file']")
[ :text_field, :password_field, :radio_button, :checkbox, :file_field,
:email, :url, :search, :tel, :color
].each do |input_type|
define_method(input_type) do |locator|
input_type = input_type.to_s.gsub("_field", "").gsub("_button", "")
add_field(locator, "//input[@type='#{input_type}']")
end
end
def scope(scope)

View File

@ -145,3 +145,26 @@
<input type="submit" value="Go FAR"/>
</p>
</form>
<form action="/form" method="post">
<p>
<label for="html5_email">Html5 Email</label>
<input type="email" name="form[html5_email]" value="person@email.com" id="html5_email"/>
</p>
<p>
<label for="html5_url">Html5 Url</label>
<input type="url" name="form[html5_url]" value="http://www.example.com" id="html5_url"/>
</p>
<p>
<label for="html5_search">Html5 Search</label>
<input type="search" name="form[html5_search]" value="what are you looking for" id="html5_search"/>
</p>
<p>
<label for="html5_tel">Html5 Tel</label>
<input type="tel" name="form[html5_tel]" value="911" id="html5_tel"/>
</p>
<p>
<label for="html5_color">Html5 Color</label>
<input type="color" name="form[html5_color]" value="#FFF" id="html5_color"/>
</p>
</form>

View File

@ -99,7 +99,7 @@ describe Capybara::XPath do
@query = @xpath.fillable_field('Description').to_s
@driver.find(@query).first.text.should == 'Descriptive text goes here'
end
it "should be chainable" do
@query = @xpath.fillable_field('First Name').password_field('First Name').to_s
@driver.find(@query).first.value.should == 'John'
@ -220,4 +220,35 @@ describe Capybara::XPath do
end
end
[ [:email, 'html5_email', 'Html5 Email', 'person@email.com'],
[:url, 'html5_url', 'Html5 Url', 'http://www.example.com'],
[:search, 'html5_search', 'Html5 Search', 'what are you looking for'],
[:tel, 'html5_tel', 'Html5 Tel', '911'],
[:color, 'html5_color', 'Html5 Color', '#FFF']].each do |method, id, label, output|
describe "##{method}" do
it "should find a file field by label" do
@query = @xpath.send(method, label).to_s
@driver.find(@query).first.value.should == output
end
it "should find a file field by id" do
@query = @xpath.send(method, id).to_s
@driver.find(@query).first.value.should == output
end
it "should be chainable" do
@query = @xpath.send(method, label).password_field(label).to_s
@driver.find(@query).first.value.should == output
@query = @xpath.send(method, 'Password').password_field('Password').to_s
@driver.find(@query).first.value.should == 'seeekrit'
end
it "should be a #fillable_field" do
@query = @xpath.fillable_field(label).to_s
@driver.find(@query).first.value.should == output
end
end
end
end