Initialize locators with a session and a dom instead of a scope

This commit is contained in:
Bryan Helmkamp 2008-11-30 15:47:31 -05:00
parent 9ace546766
commit 522bb3272f
12 changed files with 43 additions and 41 deletions

View File

@ -6,7 +6,7 @@ module Webrat
class AreaLocator < Locator
def locate
Area.load(@scope.session, area_element)
Area.load(@session, area_element)
end
def area_element
@ -21,7 +21,7 @@ module Webrat
end
def area_elements
Webrat::XML.xpath_search(@scope.dom, Area.xpath_search)
Webrat::XML.xpath_search(@dom, Area.xpath_search)
end
def error_message
@ -31,7 +31,7 @@ module Webrat
end
def find_area(id_or_title) #:nodoc:
AreaLocator.new(self, id_or_title).locate!
AreaLocator.new(@session, dom, id_or_title).locate!
end
end

View File

@ -6,7 +6,7 @@ module Webrat
class ButtonLocator < Locator
def locate
ButtonField.load(@scope.session, button_element)
ButtonField.load(@session, button_element)
end
def button_element
@ -37,7 +37,7 @@ module Webrat
end
def button_elements
Webrat::XML.xpath_search(@scope.dom, *ButtonField.xpath_search)
Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
end
def error_message
@ -47,7 +47,7 @@ module Webrat
end
def find_button(value) #:nodoc:
ButtonLocator.new(self, value).locate!
ButtonLocator.new(@session, dom, value).locate!
end
end

View File

@ -6,7 +6,7 @@ module Webrat
class FieldByIdLocator < Locator
def locate
Field.load(@scope.session, field_element)
Field.load(@session, field_element)
end
def field_element
@ -20,7 +20,7 @@ module Webrat
end
def field_elements
Webrat::XML.xpath_search(@scope.dom, *Field.xpath_search)
Webrat::XML.xpath_search(@dom, *Field.xpath_search)
end
def error_message
@ -30,7 +30,7 @@ module Webrat
end
def field_with_id(id, *field_types)
FieldByIdLocator.new(self, id, *field_types).locate!
FieldByIdLocator.new(@session, dom, id, *field_types).locate!
end
end

View File

@ -14,7 +14,7 @@ module Webrat
matching_label_elements.sort_by do |label_element|
text(label_element).length
end.map do |label_element|
Label.load(@scope.session, label_element)
Label.load(@session, label_element)
end
end
@ -25,7 +25,7 @@ module Webrat
end
def label_elements
Webrat::XML.xpath_search(@scope.dom, Label.xpath_search)
Webrat::XML.xpath_search(@dom, Label.xpath_search)
end
def error_message
@ -43,7 +43,7 @@ module Webrat
end
def field_labeled(label, *field_types)
FieldLabeledLocator.new(self, label, *field_types).locate!
FieldLabeledLocator.new(@session, dom, label, *field_types).locate!
end
end

View File

@ -6,9 +6,9 @@ module Webrat
class FieldLocator < Locator
def locate
FieldByIdLocator.new(@scope, @value).locate ||
FieldNamedLocator.new(@scope, @value, *@field_types).locate ||
FieldLabeledLocator.new(@scope, @value, *@field_types).locate
FieldByIdLocator.new(@session, @dom, @value).locate ||
FieldNamedLocator.new(@session, @dom, @value, *@field_types).locate ||
FieldLabeledLocator.new(@session, @dom, @value, *@field_types).locate
end
def error_message
@ -18,7 +18,7 @@ module Webrat
end
def field(*args) # :nodoc:
FieldLocator.new(self, *args).locate!
FieldLocator.new(@session, dom, *args).locate!
end
end

View File

@ -6,7 +6,7 @@ module Webrat
class FieldNamedLocator < Locator
def locate
Field.load(@scope.session, field_element)
Field.load(@session, field_element)
end
def field_element
@ -16,7 +16,7 @@ module Webrat
end
def field_elements
Webrat::XML.xpath_search(@scope.dom, *xpath_searches)
Webrat::XML.xpath_search(@dom, *xpath_searches)
end
def xpath_searches
@ -34,7 +34,7 @@ module Webrat
end
def field_named(name, *field_types)
FieldNamedLocator.new(self, name, *field_types).locate!
FieldNamedLocator.new(@session, dom, name, *field_types).locate!
end
end

View File

@ -6,11 +6,11 @@ module Webrat
class FormLocator < Locator
def locate
Form.load(@scope.session, form_element)
Form.load(@session, form_element)
end
def form_element
Webrat::XML.css_at(@scope.dom, "#" + @value)
Webrat::XML.css_at(@dom, "#" + @value)
end
end

View File

@ -7,7 +7,7 @@ module Webrat
class LabelLocator < Locator
def locate
Label.load(@scope.session, label_element)
Label.load(@session, label_element)
end
def label_element
@ -17,7 +17,7 @@ module Webrat
end
def label_elements
Webrat::XML.xpath_search(@scope.dom, Label.xpath_search)
Webrat::XML.xpath_search(@dom, Label.xpath_search)
end
def text(label_element)

View File

@ -6,7 +6,7 @@ module Webrat
class LinkLocator < Locator
def locate
Link.load(@scope.session, link_element)
Link.load(@session, link_element)
end
def link_element
@ -41,7 +41,7 @@ module Webrat
end
def link_elements
Webrat::XML.css_search(@scope.dom, *Link.css_search)
Webrat::XML.css_search(@dom, *Link.css_search)
end
def replace_nbsp(str)
@ -59,7 +59,7 @@ module Webrat
end
def find_link(text_or_title_or_id) #:nodoc:
LinkLocator.new(self, text_or_title_or_id).locate!
LinkLocator.new(@session, dom, text_or_title_or_id).locate!
end
end

View File

@ -3,8 +3,9 @@ module Webrat
class Locator
def initialize(scope, value, *field_types)
@scope = scope
def initialize(session, dom, value, *field_types)
@session = session
@dom = dom
@value = value
@field_types = field_types
end

View File

@ -6,15 +6,16 @@ module Webrat
class SelectOptionLocator < Locator
def initialize(scope, option_text, id_or_name_or_label)
@scope = scope
def initialize(session, dom, option_text, id_or_name_or_label)
@session = session
@dom = dom
@option_text = option_text
@id_or_name_or_label = id_or_name_or_label
end
def locate
if @id_or_name_or_label
field = FieldLocator.new(@scope, @id_or_name_or_label, SelectField).locate!
field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!
field.send(:options).detect do |o|
if @option_text.is_a?(Regexp)
@ -32,12 +33,12 @@ module Webrat
end
end
SelectOption.load(@scope.session, option_element)
SelectOption.load(@session, option_element)
end
end
def option_elements
Webrat::XML.xpath_search(@scope.dom, *SelectOption.xpath_search)
Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
end
def error_message
@ -51,7 +52,7 @@ module Webrat
end
def find_select_option(option_text, id_or_name_or_label) #:nodoc:
SelectOptionLocator.new(self, option_text, id_or_name_or_label).locate!
SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
end
end

View File

@ -132,7 +132,7 @@ module Webrat
date_to_select : Date.parse(date_to_select)
id_prefix = locate_id_prefix(options) do
year_field = FieldByIdLocator.new(self, /(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/).locate
year_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/).locate
raise NotFoundError.new("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
$1
end
@ -166,7 +166,7 @@ module Webrat
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
id_prefix = locate_id_prefix(options) do
hour_field = FieldByIdLocator.new(self, /(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/).locate
hour_field = FieldByIdLocator.new(@session, dom, /(.*?)_#{DATE_TIME_SUFFIXES[:hour]}$/).locate
raise NotFoundError.new("No time fields were found") unless hour_field && hour_field.id =~ /(.*?)_4i/
$1
end
@ -188,7 +188,7 @@ module Webrat
def select_datetime(time_to_select, options ={})
time = time_to_select.is_a?(Time) ? time_to_select : Time.parse(time_to_select)
options[:id_prefix] ||= (options[:from] ? FieldByIdLocator.new(self, options[:from]).locate : nil)
options[:id_prefix] ||= (options[:from] ? FieldByIdLocator.new(@session, dom, options[:from]).locate : nil)
select_date time, options
select_time time, options
@ -261,7 +261,7 @@ module Webrat
webrat_deprecate :clicks_button, :click_button
def submit_form(id)
FormLocator.new(self, id).locate.submit
FormLocator.new(@session, dom, id).locate.submit
end
def dom # :nodoc:
@ -301,7 +301,7 @@ module Webrat
return options[:id_prefix] if options[:id_prefix]
if options[:from]
if (label = LabelLocator.new(self, options[:from]).locate)
if (label = LabelLocator.new(@session, dom, options[:from]).locate)
label.for_id
else
raise NotFoundError.new("Could not find the label with text #{options[:from]}")