lib/page-object/accessors.rb in page-object-1.2.0 vs lib/page-object/accessors.rb in page-object-1.2.1
- old
+ new
@@ -194,11 +194,11 @@
#
# @param [String] the name used for the generated methods
# @param [Hash] identifier how we find a text field. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :label => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
@@ -230,11 +230,11 @@
#
# @param [String] the name used for the generated methods
# @param [Hash] identifier how we find a hidden field. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :value => Watir and Selenium
@@ -262,11 +262,11 @@
#
# @param [String] the name used for the generated methods
# @param [Hash] identifier how we find a text area. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# * :label => Watir and Selenium
@@ -298,11 +298,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a select list. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir only
# * :value => Watir only
@@ -374,11 +374,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a checkbox. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
@@ -414,11 +414,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a radio button. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
@@ -589,11 +589,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a table. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
@@ -623,11 +623,11 @@
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :xpath => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def cell(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'cell_for', &block)
define_method("#{name}") do
@@ -666,32 +666,37 @@
self.send("#{name}_element").text
end
end
#
- # adds two methods - one to retrieve the image element, and another to
- # check the image's existence.
+ # adds three methods - one to retrieve the image element, another to
+ # check the load status of the image, and another to check the
+ # image's existence.
#
# @example
# image(:logo, :id => 'logo')
- # # will generate 'logo_element' and 'logo?' methods
+ # # will generate 'logo_element', 'logo_loaded?', and 'logo?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find an image. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :alt => Watir and Selenium
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :src => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def image(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'image_for', &block)
+ define_method("#{name}_loaded?") do
+ return platform.image_loaded_for identifier.clone unless block_given?
+ self.send("#{name}_element").loaded?
+ end
end
alias_method :img, :image
#
# adds two methods - one to retrieve the form element, and another to
@@ -704,11 +709,11 @@
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a form. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :action => Watir and Selenium
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
@@ -757,11 +762,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find an unordered list. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
@@ -786,11 +791,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find an ordered list. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
@@ -1004,11 +1009,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a file_field. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :title => Watir and Selenium
# * :xpath => Watir and Selenium
@@ -1213,11 +1218,11 @@
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a svg. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
@@ -1238,41 +1243,63 @@
# @param [Symbol] the name used for the generated methods
# @param [Symbol] the name of the tag for the element
# @param [Hash] identifier how we find an element. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def element(name, tag=:element, identifier={ :index => 0 }, &block)
- # default tag to :element
#
- # element 'button', css: 'some css'
+ # sets tag as element if not defined
#
- # is the same as
- #
- # element 'button', :element, css: 'some css'
- #
if tag.is_a?(Hash)
identifier = tag
tag = :element
end
+ standard_methods(name, identifier, 'element_for', &block)
+
define_method("#{name}") do
- self.send("#{name}_element").text
+ element = self.send("#{name}_element")
+
+ %w(Button TextField Radio Hidden CheckBox FileField).each do |klass|
+ next unless element.element.class.to_s == "Watir::#{klass}"
+ self.class.send(klass.gsub(/(.)([A-Z])/,'\1_\2').downcase, name, identifier, &block)
+ return self.send name
+ end
+ element.text
end
define_method("#{name}_element") do
return call_block(&block) if block_given?
platform.element_for(tag, identifier.clone)
end
define_method("#{name}?") do
self.send("#{name}_element").exists?
end
+ define_method("#{name}=") do |value|
+ element = self.send("#{name}_element")
+
+ klass = case element.element
+ when Watir::TextField
+ 'text_field'
+ when Watir::TextArea
+ 'text_area'
+ when Watir::Select
+ 'select_list'
+ when Watir::FileField
+ 'file_field'
+ else
+ raise "Can not set a #{element.element} element with #="
+ end
+ self.class.send(klass, name, identifier, &block)
+ self.send("#{name}=", value)
+ end
end
#
# adds a method to return a collection of generic Element objects
# for a specific tag.
@@ -1284,26 +1311,21 @@
# @param [Symbol] the name used for the generated methods
# @param [Symbol] the name of the tag for the element
# @param [Hash] identifier how we find an element. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def elements(name, tag=:element, identifier={:index => 0}, &block)
- # default tag to :element
#
- # elements 'button', css: 'some css'
+ # sets tag as element if not defined
#
- # is the same as
- #
- # elements 'button', :element, css: 'some css'
- #
if tag.is_a?(Hash)
identifier = tag
tag = :element
end
@@ -1323,11 +1345,11 @@
# @param [Symbol] the name used for the generated methods
# @param [Class] the class to instantiate for the element
# @param [Hash] identifier how we find an element. You can use multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
#
@@ -1347,11 +1369,11 @@
# @param [Symbol] the name used for the generated method
# @param [Class] the class to instantiate for each element
# @param [Hash] identifier how we find an element. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
#
@@ -1374,10 +1396,10 @@
# @param [Symbol] the name used for the generated methods
# @param [Symbol] the name of the tag for the element
# @param [Hash] identifier how we find an element. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
- # * :css => Selenium only
+ # * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called