mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added select
This commit is contained in:
parent
d21ce44ef5
commit
48993cf7bb
4 changed files with 30 additions and 10 deletions
|
@ -19,6 +19,10 @@ class Webcat::Driver::Culerity
|
||||||
node.set(value.to_s)
|
node.set(value.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def select(option)
|
||||||
|
node.select(option)
|
||||||
|
end
|
||||||
|
|
||||||
def click
|
def click
|
||||||
node.click
|
node.click
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,11 @@ class Webcat::Driver::RackTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def select(option)
|
||||||
|
node.xpath(".//option").each { |node| node.remove_attribute("selected") }
|
||||||
|
node.xpath(".//option[text()='#{option}']").first["selected"] = 'selected'
|
||||||
|
end
|
||||||
|
|
||||||
def click
|
def click
|
||||||
if tag_name == 'a'
|
if tag_name == 'a'
|
||||||
session.visit(self[:href])
|
session.visit(self[:href])
|
||||||
|
|
|
@ -49,6 +49,10 @@ class Webcat::Session
|
||||||
find_field(locator, :checkbox).set(false)
|
find_field(locator, :checkbox).set(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def select(value, options={})
|
||||||
|
find_field(options[:from], :select).select(value)
|
||||||
|
end
|
||||||
|
|
||||||
def body
|
def body
|
||||||
driver.body
|
driver.body
|
||||||
end
|
end
|
||||||
|
@ -73,7 +77,8 @@ private
|
||||||
: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}']" },
|
:radio => proc { |id| "//input[@type='radio'][@id='#{id}']" },
|
||||||
:hidden_field => proc { |id| "//input[@type='hidden'][@id='#{id}']" },
|
:hidden_field => proc { |id| "//input[@type='hidden'][@id='#{id}']" },
|
||||||
:checkbox => proc { |id| "//input[@type='checkbox'][@id='#{id}']" }
|
:checkbox => proc { |id| "//input[@type='checkbox'][@id='#{id}']" },
|
||||||
|
:select => proc { |id| "//select[@id='#{id}']" }
|
||||||
}
|
}
|
||||||
|
|
||||||
def find_field_by_id(locator, *kinds)
|
def find_field_by_id(locator, *kinds)
|
||||||
|
|
|
@ -246,20 +246,26 @@ shared_examples_for "session" do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#select" do
|
describe "#select" do
|
||||||
|
before do
|
||||||
|
@session.visit('/form')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#unselect" do
|
it "should select an option from a select box by id" do
|
||||||
|
@session.select("Finish", :from => 'form_locale')
|
||||||
|
@session.click_button('awesome')
|
||||||
|
YAML.load(@session.body)['locale'].should == 'fi'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should select an option from a select box by label" do
|
||||||
|
@session.select("Finish", :from => 'Locale')
|
||||||
|
@session.click_button('awesome')
|
||||||
|
YAML.load(@session.body)['locale'].should == 'fi'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#attach_file" do
|
describe "#attach_file" do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#submit_form" do
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Webcat::Session do
|
describe Webcat::Session do
|
||||||
|
|
Loading…
Reference in a new issue