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)
|
||||
end
|
||||
|
||||
def select(option)
|
||||
node.select(option)
|
||||
end
|
||||
|
||||
def click
|
||||
node.click
|
||||
end
|
||||
|
|
|
@ -29,6 +29,11 @@ class Webcat::Driver::RackTest
|
|||
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
|
||||
if tag_name == 'a'
|
||||
session.visit(self[:href])
|
||||
|
|
|
@ -49,6 +49,10 @@ class Webcat::Session
|
|||
find_field(locator, :checkbox).set(false)
|
||||
end
|
||||
|
||||
def select(value, options={})
|
||||
find_field(options[:from], :select).select(value)
|
||||
end
|
||||
|
||||
def body
|
||||
driver.body
|
||||
end
|
||||
|
@ -73,7 +77,8 @@ private
|
|||
:password_field => proc { |id| "//input[@type='password'][@id='#{id}']" },
|
||||
:radio => proc { |id| "//input[@type='radio'][@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)
|
||||
|
|
|
@ -246,20 +246,26 @@ shared_examples_for "session" do
|
|||
end
|
||||
|
||||
describe "#select" do
|
||||
|
||||
before do
|
||||
@session.visit('/form')
|
||||
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
|
||||
|
||||
describe "#attach_file" do
|
||||
|
||||
end
|
||||
|
||||
describe "#submit_form" do
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe Webcat::Session do
|
||||
|
|
Loading…
Reference in a new issue