Working on SelectOptionLocator
This commit is contained in:
parent
e72bba29c7
commit
ac4feb3b7e
@ -13,6 +13,8 @@ module Webrat
|
|||||||
session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
|
session.elements[Webrat::XML.xpath_to(element)] ||= self.new(session, element)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_reader :element
|
||||||
|
|
||||||
def initialize(session, element)
|
def initialize(session, element)
|
||||||
@session = session
|
@session = session
|
||||||
@element = element
|
@element = element
|
||||||
|
@ -69,11 +69,6 @@ module Webrat
|
|||||||
Webrat::XML.attribute(@element, "name") == name.to_s
|
Webrat::XML.attribute(@element, "name") == name.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_label?(label_text)
|
|
||||||
return false if labels.empty?
|
|
||||||
labels.any? { |label| label.matches_text?(label_text) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def disabled?
|
def disabled?
|
||||||
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
|
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
|
||||||
end
|
end
|
||||||
|
@ -14,12 +14,9 @@ module Webrat
|
|||||||
def find_select_option(option_text)
|
def find_select_option(option_text)
|
||||||
select_fields = fields_by_type([SelectField])
|
select_fields = fields_by_type([SelectField])
|
||||||
|
|
||||||
select_fields.each do |select_field|
|
select_fields.detect_mapped do |select_field|
|
||||||
result = select_field.find_option(option_text)
|
select_field.find_option(option_text)
|
||||||
return result if result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def fields
|
def fields
|
||||||
|
@ -36,14 +36,6 @@ module Webrat
|
|||||||
replace_nbsp(text) =~ matcher || replace_nbsp_ref(inner_html) =~ matcher || title =~ matcher
|
replace_nbsp(text) =~ matcher || replace_nbsp_ref(inner_html) =~ matcher || title =~ matcher
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_id?(id_or_regexp)
|
|
||||||
if id_or_regexp.is_a?(Regexp)
|
|
||||||
(id =~ id_or_regexp) ? true : false
|
|
||||||
else
|
|
||||||
(id == id_or_regexp) ? true : false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def inner_html
|
def inner_html
|
||||||
Webrat::XML.inner_html(@element)
|
Webrat::XML.inner_html(@element)
|
||||||
end
|
end
|
||||||
|
@ -7,14 +7,6 @@ module Webrat
|
|||||||
".//option"
|
".//option"
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_text?(text)
|
|
||||||
if text.is_a?(Regexp)
|
|
||||||
Webrat::XML.inner_html(@element) =~ text
|
|
||||||
else
|
|
||||||
Webrat::XML.inner_html(@element) == text.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def choose
|
def choose
|
||||||
select.raise_error_if_disabled
|
select.raise_error_if_disabled
|
||||||
select.set(value)
|
select.set(value)
|
||||||
|
@ -15,11 +15,27 @@ module Webrat
|
|||||||
def locate
|
def locate
|
||||||
# TODO - Convert to using elements
|
# TODO - Convert to using elements
|
||||||
if @id_or_name_or_label
|
if @id_or_name_or_label
|
||||||
field = @scope.field(@id_or_name_or_label, SelectField)
|
field = FieldLocator.new(@scope, @id_or_name_or_label, SelectField).locate!
|
||||||
field.find_option(@option_text)
|
|
||||||
|
field.send(:options).detect do |o|
|
||||||
|
if @option_text.is_a?(Regexp)
|
||||||
|
Webrat::XML.inner_html(o.element) =~ @option_text
|
||||||
|
else
|
||||||
|
Webrat::XML.inner_html(o.element) == @option_text.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@scope.send(:forms).detect_mapped do |form|
|
@scope.send(:forms).detect_mapped do |form|
|
||||||
form.find_select_option(@option_text)
|
select_fields = form.send(:fields_by_type, [SelectField])
|
||||||
|
select_fields.detect_mapped do |select_field|
|
||||||
|
select_field.send(:options).detect do |o|
|
||||||
|
if @option_text.is_a?(Regexp)
|
||||||
|
Webrat::XML.inner_html(o.element) =~ @option_text
|
||||||
|
else
|
||||||
|
Webrat::XML.inner_html(o.element) == @option_text.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -79,22 +79,4 @@ describe Webrat::Link do
|
|||||||
link.matches_text?('logo.png').should == 10
|
link.matches_text?('logo.png').should == 10
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should matches_id? on exact matching id" do
|
|
||||||
link = Webrat::Link.new(webrat_session, nil)
|
|
||||||
link.should_receive(:id).and_return("some_id")
|
|
||||||
link.matches_id?("some_id").should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should not matches_id? on incorrect id" do
|
|
||||||
link = Webrat::Link.new(webrat_session, nil)
|
|
||||||
link.should_receive(:id).and_return("other_id")
|
|
||||||
link.matches_id?("some_id").should == false
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should matches_id? on matching id by regexp" do
|
|
||||||
link = Webrat::Link.new(webrat_session, nil)
|
|
||||||
link.should_receive(:id).and_return("some_id")
|
|
||||||
link.matches_id?(/some/).should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user