Class: PageObject::Elements::Element

Inherits:
Object
  • Object
show all
Includes:
NestedElements
Defined in:
lib/page-object/elements/element.rb

Overview

Contains functionality that is common across all elements.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NestedElements

included

Constructor Details

#initialize(element, platform) ⇒ Element

Returns a new instance of Element.



16
17
18
19
# File 'lib/page-object/elements/element.rb', line 16

def initialize(element, platform)
  @element = element
  include_platform_for platform
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

delegate calls to driver element



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/page-object/elements/element.rb', line 103

def method_missing(*args, &block)
  m = args.shift
  $stderr.puts "*** DEPRECATION WARNING"
  $stderr.puts "*** You are calling a method named #{m} at #{caller[0]}."
  $stderr.puts "*** This method does not exist in page-object so it is being passed to the driver."
  $stderr.puts "*** This feature will be removed in the near future."
  $stderr.puts "*** Please change your code to call the correct page-object method."
  $stderr.puts "*** If you are using functionality that does not exist in page-object please request it be added."
  begin
    element.send m, *args, &block
  rescue Exception => e
    raise
  end
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



14
15
16
# File 'lib/page-object/elements/element.rb', line 14

def element
  @element
end

Class Method Details

.plural_formObject

specify plural form of element



65
66
67
68
69
70
71
# File 'lib/page-object/elements/element.rb', line 65

def self.plural_form
  "#{self.to_s.split('::')[-1].
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase}s"
end

.selenium_identifier_for(identifier) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/page-object/elements/element.rb', line 90

def self.selenium_identifier_for identifier
  if identifier.length == 1
    identifier = identifier_for identifier, selenium_finders, selenium_mapping
    return identifier.keys.first, identifier.values.first
  elsif identifier.length > 1
    how = :xpath
    what = build_xpath_for identifier
    return how, what
  end
end

.watir_identifier_for(identifier) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/page-object/elements/element.rb', line 74

def self.watir_identifier_for identifier
  if should_build_watir_xpath(identifier)
    how = :xpath
    what = build_xpath_for(identifier)
    return how => what
  end
  all_identities = {}
  identifier.each do |key, value|
    each = {key => value}
    ident = identifier_for each, watir_finders, watir_mapping
    all_identities[ident.keys.first] = ident.values.first
  end
  all_identities
end

Instance Method Details

#class_nameObject

retrieve the class name for an element



58
59
60
# File 'lib/page-object/elements/element.rb', line 58

def class_name
  attribute 'class'
end

#clickObject

click the element



24
25
26
# File 'lib/page-object/elements/element.rb', line 24

def click
  element.click
end

#disabled?Boolean

return true if the element is not enabled

Returns:

  • (Boolean)


40
41
42
# File 'lib/page-object/elements/element.rb', line 40

def disabled?
  not enabled?
end

#enabled?Boolean

return true if the element is enabled

Returns:

  • (Boolean)


33
34
35
# File 'lib/page-object/elements/element.rb', line 33

def enabled?
  element.enabled?
end

#inspectObject



51
52
53
# File 'lib/page-object/elements/element.rb', line 51

def inspect
  element.inspect
end

#style(property) ⇒ Object

get the value of the given CSS property



47
48
49
# File 'lib/page-object/elements/element.rb', line 47

def style(property)
  element.style property
end