page-object 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/ChangeLog +9 -0
  4. data/Gemfile +1 -0
  5. data/features/section.feature +4 -0
  6. data/features/step_definitions/section_steps.rb +10 -1
  7. data/lib/page-object.rb +16 -8
  8. data/lib/page-object/accessors.rb +2 -2
  9. data/lib/page-object/elements/button.rb +0 -7
  10. data/lib/page-object/elements/canvas.rb +1 -13
  11. data/lib/page-object/elements/check_box.rb +0 -12
  12. data/lib/page-object/elements/element.rb +52 -9
  13. data/lib/page-object/elements/file_field.rb +0 -12
  14. data/lib/page-object/elements/form.rb +0 -12
  15. data/lib/page-object/elements/image.rb +0 -12
  16. data/lib/page-object/elements/link.rb +0 -12
  17. data/lib/page-object/elements/ordered_list.rb +0 -13
  18. data/lib/page-object/elements/radio_button.rb +0 -12
  19. data/lib/page-object/elements/select_list.rb +0 -13
  20. data/lib/page-object/elements/table.rb +0 -13
  21. data/lib/page-object/elements/table_row.rb +0 -13
  22. data/lib/page-object/elements/text_area.rb +0 -14
  23. data/lib/page-object/elements/text_field.rb +0 -12
  24. data/lib/page-object/elements/unordered_list.rb +0 -12
  25. data/lib/page-object/elements/video.rb +0 -10
  26. data/lib/page-object/platforms/selenium_webdriver/element.rb +1 -1
  27. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +26 -5
  28. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +1 -1
  29. data/lib/page-object/platforms/selenium_webdriver/table.rb +1 -1
  30. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +1 -1
  31. data/lib/page-object/platforms/watir_webdriver/element.rb +9 -2
  32. data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +1 -1
  33. data/lib/page-object/platforms/watir_webdriver/page_object.rb +25 -4
  34. data/lib/page-object/platforms/watir_webdriver/select_list.rb +1 -1
  35. data/lib/page-object/platforms/watir_webdriver/table.rb +1 -1
  36. data/lib/page-object/platforms/watir_webdriver/table_row.rb +1 -1
  37. data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +1 -1
  38. data/lib/page-object/section_collection.rb +16 -0
  39. data/lib/page-object/version.rb +1 -1
  40. data/lib/page-object/widgets.rb +14 -36
  41. data/spec/page-object/elements/canvas_spec.rb +3 -2
  42. data/spec/page-object/elements/ordered_list_spec.rb +2 -2
  43. data/spec/page-object/elements/select_list_spec.rb +2 -2
  44. data/spec/page-object/elements/unordered_list_spec.rb +2 -2
  45. data/spec/page-object/elements/video_spec.rb +12 -6
  46. data/spec/page-object/page-object_spec.rb +51 -23
  47. data/spec/page-object/page_section_spec.rb +9 -2
  48. data/spec/page-object/watir_accessors_spec.rb +1 -0
  49. metadata +4 -4
  50. data/lib/page-object/sections.rb +0 -29
@@ -30,19 +30,6 @@ module PageObject
30
30
  ::PageObject::Elements::TableCell.new(row_element, platform)
31
31
  end
32
32
 
33
-
34
- def include_platform_for platform
35
- super
36
- if platform[:platform] == :watir_webdriver
37
- require 'page-object/platforms/watir_webdriver/table_row'
38
- self.class.send :include, PageObject::Platforms::WatirWebDriver::TableRow
39
- elsif platform[:platform] == :selenium_webdriver
40
- require 'page-object/platforms/selenium_webdriver/table_row'
41
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::TableRow
42
- else
43
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
44
- end
45
- end
46
33
  end
47
34
 
48
35
  ::PageObject::Elements.tag_to_class[:tr] = ::PageObject::Elements::TableRow
@@ -16,20 +16,6 @@ module PageObject
16
16
  super + [:label]
17
17
  end
18
18
 
19
- protected
20
-
21
- def include_platform_for platform
22
- super
23
- if platform[:platform] == :watir_webdriver
24
- require 'page-object/platforms/watir_webdriver/text_area'
25
- self.class.send :include, PageObject::Platforms::WatirWebDriver::TextArea
26
- elsif platform[:platform] == :selenium_webdriver
27
- require 'page-object/platforms/selenium_webdriver/text_area'
28
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::TextArea
29
- else
30
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
31
- end
32
- end
33
19
  end
34
20
 
35
21
  ::PageObject::Elements.tag_to_class[:textarea] = ::PageObject::Elements::TextArea
@@ -22,18 +22,6 @@ module PageObject
22
22
  super + [:title, :value, :text, :label]
23
23
  end
24
24
 
25
- def include_platform_for platform
26
- super
27
- if platform[:platform] == :watir_webdriver
28
- require 'page-object/platforms/watir_webdriver/text_field'
29
- self.class.send :include, PageObject::Platforms::WatirWebDriver::TextField
30
- elsif platform[:platform] == :selenium_webdriver
31
- require 'page-object/platforms/selenium_webdriver/text_field'
32
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::TextField
33
- else
34
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
35
- end
36
- end
37
25
  end
38
26
 
39
27
  ::PageObject::Elements.type_to_class[:text] = ::PageObject::Elements::TextField
@@ -31,18 +31,6 @@ module PageObject
31
31
  [:class, :id, :index, :xpath]
32
32
  end
33
33
 
34
- def include_platform_for platform
35
- super
36
- if platform[:platform] == :watir_webdriver
37
- require 'page-object/platforms/watir_webdriver/unordered_list'
38
- self.class.send :include, PageObject::Platforms::WatirWebDriver::UnorderedList
39
- elsif platform[:platform] == :selenium_webdriver
40
- require 'page-object/platforms/selenium_webdriver/unordered_list'
41
- self.class.send :include, PageObject::Platforms::SeleniumWebDriver::UnorderedList
42
- else
43
- raise ArgumentError, "expect platform to be :watir_webdriver or :selenium_webdriver"
44
- end
45
- end
46
34
  end
47
35
 
48
36
  ::PageObject::Elements.tag_to_class[:ul] = ::PageObject::Elements::UnorderedList
@@ -2,16 +2,6 @@ module PageObject
2
2
  module Elements
3
3
  class Video < Media
4
4
 
5
- def height
6
- height = attribute(:height)
7
- return height.to_i if height
8
- end
9
-
10
- def width
11
- width = attribute(:width)
12
- return width.to_i if width
13
- end
14
-
15
5
  end
16
6
  ::PageObject::Elements.type_to_class[:video] = ::PageObject::Elements::Video
17
7
  end
@@ -146,7 +146,7 @@ module PageObject
146
146
  parent = bridge.executeScript(script, element)
147
147
  type = element.attribute(:type).to_s.downcase if parent.tag_name.to_sym == :input
148
148
  cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
149
- cls.new(parent, :platform => :selenium_webdriver)
149
+ cls.new(parent, :platform => @platform.class::PLATFORM_NAME)
150
150
  end
151
151
 
152
152
  #
@@ -12,6 +12,14 @@ module PageObject
12
12
  # and use the methods dynamically added from the PageObject::Accessors module.
13
13
  #
14
14
  class PageObject
15
+
16
+ PLATFORM_NAME = :selenium_webdriver
17
+
18
+ def self.define_widget_accessors(widget_tag, widget_class, base_element_tag)
19
+ define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
20
+ define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
21
+ end
22
+
15
23
  def initialize(browser)
16
24
  @browser = browser
17
25
  end
@@ -139,7 +147,7 @@ module PageObject
139
147
  element = @browser.execute_script("return document.activeElement")
140
148
  type = element.attribute(:type).to_s.downcase if element.tag_name.to_sym == :input
141
149
  cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
142
- cls.new(element, :platform => :selenium_webdriver)
150
+ cls.new(element, :platform => self.class::PLATFORM_NAME)
143
151
  end
144
152
 
145
153
  #
@@ -1026,7 +1034,7 @@ module PageObject
1026
1034
  # See PageObject::Accessors#page_sections
1027
1035
  #
1028
1036
  def pages_for(identifier, page_class)
1029
- SectionCollection.new(find_selenium_pages(identifier, page_class))
1037
+ SectionCollection[*find_selenium_pages(identifier, page_class)]
1030
1038
  end
1031
1039
 
1032
1040
  #
@@ -1120,7 +1128,7 @@ module PageObject
1120
1128
  return build_null_object(identifier, type, tag, other)
1121
1129
  end
1122
1130
  @browser.switch_to.default_content unless frame_identifiers.nil?
1123
- type.new(element, :platform => :selenium_webdriver)
1131
+ type.new(element, :platform => self.class::PLATFORM_NAME)
1124
1132
  end
1125
1133
 
1126
1134
  def find_selenium_elements(identifier, type, tag, other=nil)
@@ -1134,7 +1142,7 @@ module PageObject
1134
1142
  elements = eles.find_all {|ele| matches_selector?(ele, regexp[0], regexp[1])}
1135
1143
  end
1136
1144
  @browser.switch_to.default_content unless frame_identifiers.nil?
1137
- elements.map { |element| type.new(element, :platform => :selenium_webdriver) }
1145
+ elements.map { |element| type.new(element, :platform => self.class::PLATFORM_NAME) }
1138
1146
  end
1139
1147
 
1140
1148
  def find_selenium_pages(identifier, page_class)
@@ -1178,7 +1186,7 @@ module PageObject
1178
1186
  null_element.tag = tag
1179
1187
  null_element.other = other
1180
1188
  null_element.platform = self
1181
- Elements::Element.new(null_element, :platform => :selenium_webdriver)
1189
+ Elements::Element.new(null_element, :platform => self.class::PLATFORM_NAME)
1182
1190
  end
1183
1191
 
1184
1192
  def delete_regexp(identifier)
@@ -1256,6 +1264,19 @@ module PageObject
1256
1264
  end
1257
1265
  end
1258
1266
  end
1267
+
1268
+ def self.define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
1269
+ send(:define_method, "#{widget_tag}s_for") do |identifier|
1270
+ find_selenium_elements(identifier, widget_class, base_element_tag)
1271
+ end
1272
+ end
1273
+
1274
+ def self.define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
1275
+ send(:define_method, "#{widget_tag}_for") do |identifier|
1276
+ find_selenium_element(identifier, widget_class, base_element_tag)
1277
+ end
1278
+ end
1279
+
1259
1280
  end
1260
1281
  end
1261
1282
  end
@@ -38,7 +38,7 @@ module PageObject
38
38
  #
39
39
  # @return [array of PageObject::Elements::Option]
40
40
  def options
41
- find_options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :selenium_webdriver) }
41
+ find_options.map { |e| ::PageObject::Elements::Option.new(e, :platform => @platform.class::PLATFORM_NAME) }
42
42
  end
43
43
 
44
44
  #
@@ -14,7 +14,7 @@ module PageObject
14
14
  eles = table_rows
15
15
  idx = find_index_by_title(idx, eles) if idx.kind_of?(String)
16
16
  return nil unless idx
17
- initialize_row(eles[idx], :platform => :selenium_webdriver)
17
+ initialize_row(eles[idx], :platform => @platform.class::PLATFORM_NAME)
18
18
  end
19
19
 
20
20
  #
@@ -14,7 +14,7 @@ module PageObject
14
14
  els = table_cells
15
15
  idx = find_index_by_title(idx) if idx.kind_of?(String)
16
16
  return nil unless idx && columns >= idx + 1
17
- initialize_cell(els[idx], :platform => :selenium_webdriver)
17
+ initialize_cell(els[idx], :platform => @platform.class::PLATFORM_NAME)
18
18
  end
19
19
 
20
20
  #
@@ -28,7 +28,14 @@ module PageObject
28
28
  def flash
29
29
  element.flash
30
30
  end
31
-
31
+
32
+ #
33
+ # Click this element
34
+ #
35
+ def right_click
36
+ element.right_click
37
+ end
38
+
32
39
  #
33
40
  # Get the text for the element
34
41
  #
@@ -134,7 +141,7 @@ module PageObject
134
141
  parent = element.parent
135
142
  type = element.type if parent.tag_name.to_sym == :input
136
143
  cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
137
- cls.new(parent, :platform => :watir_webdriver)
144
+ cls.new(parent, :platform => @platform.class::PLATFORM_NAME)
138
145
  end
139
146
 
140
147
  #
@@ -10,7 +10,7 @@ module PageObject
10
10
  # @return [PageObject::Elements::ListItem]
11
11
  #
12
12
  def [](idx)
13
- Object::PageObject::Elements::ListItem.new(children[idx], :platform => :watir_webdriver)
13
+ Object::PageObject::Elements::ListItem.new(children[idx], :platform => @platform.class::PLATFORM_NAME)
14
14
  end
15
15
 
16
16
  #
@@ -6,6 +6,7 @@ require 'page-object/core_ext/string'
6
6
  module PageObject
7
7
  module Platforms
8
8
  module WatirWebDriver
9
+
9
10
  #
10
11
  # Watir implementation of the page object platform driver. You should not use the
11
12
  # class directly. Instead you should include the PageObject module in your page object
@@ -14,6 +15,13 @@ module PageObject
14
15
  class PageObject
15
16
  attr_reader :browser
16
17
 
18
+ PLATFORM_NAME = :watir_webdriver
19
+
20
+ def self.define_widget_accessors(widget_tag, widget_class, base_element_tag)
21
+ define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
22
+ define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
23
+ end
24
+
17
25
  def initialize(browser)
18
26
  @browser = browser
19
27
  end
@@ -132,7 +140,8 @@ module PageObject
132
140
  element = browser.execute_script("return document.activeElement")
133
141
  type = element.type.to_sym if element.tag_name.to_sym == :input
134
142
  cls = ::PageObject::Elements.element_class_for(element.tag_name, type)
135
- cls.new(element, :platform => :watir_webdriver)
143
+ # cls.new(element, :platform => :watir_webdriver)
144
+ cls.new(element, :platform => self.class::PLATFORM_NAME)
136
145
  end
137
146
 
138
147
  #
@@ -954,7 +963,7 @@ module PageObject
954
963
  # See PageObject::Accessors#page_sections
955
964
  #
956
965
  def pages_for(identifier, page_class)
957
- SectionCollection.new(find_watir_pages(identifier, page_class))
966
+ SectionCollection[*find_watir_pages(identifier, page_class)]
958
967
  end
959
968
 
960
969
  #
@@ -1023,14 +1032,14 @@ module PageObject
1023
1032
  identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1024
1033
  elements = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1025
1034
  switch_to_default_content(frame_identifiers)
1026
- elements.map { |element| type.new(element, :platform => :watir_webdriver) }
1035
+ elements.map { |element| type.new(element, :platform => self.class::PLATFORM_NAME) }
1027
1036
  end
1028
1037
 
1029
1038
  def find_watir_element(the_call, type, identifier, tag_name=nil)
1030
1039
  identifier, frame_identifiers = parse_identifiers(identifier, type, tag_name)
1031
1040
  element = @browser.instance_eval "#{nested_frames(frame_identifiers)}#{the_call}"
1032
1041
  switch_to_default_content(frame_identifiers)
1033
- type.new(element, :platform => :watir_webdriver)
1042
+ type.new(element, :platform => self.class::PLATFORM_NAME)
1034
1043
  end
1035
1044
 
1036
1045
  def find_watir_pages(identifier, page_class)
@@ -1099,6 +1108,18 @@ module PageObject
1099
1108
  end
1100
1109
  end
1101
1110
  end
1111
+
1112
+ def self.define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
1113
+ send(:define_method, "#{widget_tag}s_for") do |identifier|
1114
+ find_watir_elements("#{base_element_tag}s(identifier)", widget_class, identifier, base_element_tag)
1115
+ end
1116
+ end
1117
+
1118
+ def self.define_widget_singular_accessor(base_element_tag, widget_class, widget_tag)
1119
+ send(:define_method, "#{widget_tag}_for") do |identifier|
1120
+ find_watir_element("#{base_element_tag}(identifier)", widget_class, identifier, base_element_tag)
1121
+ end
1122
+ end
1102
1123
  end
1103
1124
  end
1104
1125
  end
@@ -34,7 +34,7 @@ module PageObject
34
34
  # @return [array of PageObject::Elements::Option]
35
35
  #
36
36
  def options
37
- element.options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :watir_webdriver) }
37
+ element.options.map { |e| ::PageObject::Elements::Option.new(e, :platform => @platform.class::PLATFORM_NAME) }
38
38
  end
39
39
 
40
40
  #
@@ -14,7 +14,7 @@ module PageObject
14
14
  def [](idx)
15
15
  idx = find_index_by_title(idx) if idx.kind_of?(String)
16
16
  return nil unless idx
17
- initialize_row(element[idx], :platform => :watir_webdriver)
17
+ initialize_row(element[idx], :platform => @platform.class::PLATFORM_NAME)
18
18
  end
19
19
 
20
20
  #
@@ -12,7 +12,7 @@ module PageObject
12
12
  def [](idx)
13
13
  idx = find_index_by_title(idx) if idx.kind_of?(String)
14
14
  return nil unless idx && columns >= idx + 1
15
- initialize_cell(element[idx], :platform => :watir_webdriver)
15
+ initialize_cell(element[idx], :platform => @platform.class::PLATFORM_NAME)
16
16
  end
17
17
 
18
18
  #
@@ -10,7 +10,7 @@ module PageObject
10
10
  # @return [PageObject::Elements::ListItem]
11
11
  #
12
12
  def [](idx)
13
- Object::PageObject::Elements::ListItem.new(children[idx], :platform => :watir_webdriver)
13
+ Object::PageObject::Elements::ListItem.new(children[idx], :platform => @platform.class::PLATFORM_NAME)
14
14
  end
15
15
 
16
16
  #
@@ -0,0 +1,16 @@
1
+ module PageObject
2
+ class SectionCollection < Array
3
+ def find_by(values_hash)
4
+ find do |section|
5
+ values_hash.all? { |key, value| value === section.public_send(key) }
6
+ end
7
+ end
8
+
9
+ def select_by(values_hash)
10
+ matches = select do |section|
11
+ values_hash.all? { |key, value| value === section.public_send(key) }
12
+ end
13
+ self.class[*matches]
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
@@ -20,13 +20,25 @@ module PageObject
20
20
  define_accessors(Accessors, widget_tag, widget_class)
21
21
  define_nested_elements(Elements::Element, widget_tag)
22
22
  define_locators(PageObject, widget_tag)
23
- define_selenium_accessors(Platforms::SeleniumWebDriver::PageObject, widget_tag, widget_class, base_element_tag)
24
- define_watir_accessors(Platforms::WatirWebDriver::PageObject, widget_tag, widget_class, base_element_tag)
23
+
24
+ PageObject::Platforms.constants.each { |platform|
25
+ platform_class = constantize_classname("PageObject::Platforms::#{platform}::PageObject")
26
+ if platform_class.respond_to?(:define_widget_accessors)
27
+ platform_class.send(:define_widget_accessors,widget_tag, widget_class, base_element_tag)
28
+ else
29
+ $stderr.puts "*** WARNING"
30
+ $stderr.puts "*** Platform PageObject::Platforms::#{platform} does not support widgets! Please add the 'define_widget_accessors' method in PageObject::Platforms::#{platform}::PageObject to support widgets."
31
+ end
32
+ }
25
33
  end
26
34
  end
27
35
 
28
36
  private
29
37
 
38
+ def self.constantize_classname name
39
+ name.split("::").inject(Object) { |k,n| k.const_get(n) }
40
+ end
41
+
30
42
  def self.define_accessors(base, widget_tag, widget_class)
31
43
  accessors_module = Module.new do
32
44
  define_method widget_tag do |name, *identifier_args, &block|
@@ -58,40 +70,6 @@ module PageObject
58
70
  base.send(:include, accessors_module)
59
71
  end
60
72
 
61
- def self.define_watir_accessors(base, widget_tag, widget_class, base_element_tag)
62
- define_singular_watir_accessor(base, base_element_tag, widget_class, widget_tag)
63
- define_multiple_watir_accessor(base, base_element_tag, widget_class, widget_tag)
64
- end
65
-
66
- def self.define_multiple_watir_accessor(base, base_element_tag, widget_class, widget_tag)
67
- base.send(:define_method, "#{widget_tag}s_for") do |identifier|
68
- find_watir_elements("#{base_element_tag}s(identifier)", widget_class, identifier, base_element_tag)
69
- end
70
- end
71
-
72
- def self.define_singular_watir_accessor(base, base_element_tag, widget_class, widget_tag)
73
- base.send(:define_method, "#{widget_tag}_for") do |identifier|
74
- find_watir_element("#{base_element_tag}(identifier)", widget_class, identifier, base_element_tag)
75
- end
76
- end
77
-
78
- def self.define_selenium_accessors(base, widget_tag, widget_class, base_element_tag)
79
- define_singular_selenium_accessor(base, base_element_tag, widget_class, widget_tag)
80
- define_multiple_selenium_accessor(base, base_element_tag, widget_class, widget_tag)
81
- end
82
-
83
- def self.define_multiple_selenium_accessor(base, base_element_tag, widget_class, widget_tag)
84
- base.send(:define_method, "#{widget_tag}s_for") do |identifier|
85
- find_selenium_elements(identifier, widget_class, base_element_tag)
86
- end
87
- end
88
-
89
- def self.define_singular_selenium_accessor(base, base_element_tag, widget_class, widget_tag)
90
- base.send(:define_method, "#{widget_tag}_for") do |identifier|
91
- find_selenium_element(identifier, widget_class, base_element_tag)
92
- end
93
- end
94
-
95
73
  def self.define_nested_elements(base, widget_tag)
96
74
  define_singular_nested_accessor(base, widget_tag)
97
75
  define_multiple_nested_accessor(base, widget_tag)