added basic html5 input types
This commit is contained in:
parent
98e14103e1
commit
bb887c5d1d
|
@ -38,7 +38,8 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def fillable_field(locator)
|
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
|
end
|
||||||
|
|
||||||
def content(locator)
|
def content(locator)
|
||||||
|
@ -62,32 +63,21 @@ module Capybara
|
||||||
xpath.append("//button[@id=#{s(locator)} or contains(@value,#{s(locator)}) or contains(.,#{s(locator)})]")
|
xpath.append("//button[@id=#{s(locator)} or contains(@value,#{s(locator)}) or contains(.,#{s(locator)})]")
|
||||||
end
|
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)
|
def text_area(locator)
|
||||||
add_field(locator, "//textarea")
|
add_field(locator, "//textarea")
|
||||||
end
|
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)
|
def select(locator)
|
||||||
add_field(locator, "//select")
|
add_field(locator, "//select")
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_field(locator)
|
[ :text_field, :password_field, :radio_button, :checkbox, :file_field,
|
||||||
add_field(locator, "//input[@type='file']")
|
: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
|
end
|
||||||
|
|
||||||
def scope(scope)
|
def scope(scope)
|
||||||
|
|
|
@ -145,3 +145,26 @@
|
||||||
<input type="submit" value="Go FAR"/>
|
<input type="submit" value="Go FAR"/>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</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>
|
||||||
|
|
|
@ -220,4 +220,35 @@ describe Capybara::XPath do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue