Added select

This commit is contained in:
Jonas Nicklas 2009-11-11 22:54:02 +01:00
parent d21ce44ef5
commit 48993cf7bb
4 changed files with 30 additions and 10 deletions

View File

@ -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

View File

@ -28,6 +28,11 @@ class Webcat::Driver::RackTest
node.content = value.to_s
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'

View File

@ -48,6 +48,10 @@ class Webcat::Session
def uncheck(locator)
find_field(locator, :checkbox).set(false)
end
def select(value, options={})
find_field(options[:from], :select).select(value)
end
def body
driver.body
@ -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)

View File

@ -246,20 +246,26 @@ shared_examples_for "session" do
end
describe "#select" do
end
describe "#unselect" do
before do
@session.visit('/form')
end
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