page-object 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -1
  3. data/.gitignore +8 -8
  4. data/.rspec +2 -2
  5. data/.ruby-gemset +1 -1
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +17 -17
  8. data/ChangeLog +923 -888
  9. data/Gemfile +13 -13
  10. data/Guardfile +20 -20
  11. data/LICENSE +20 -20
  12. data/README.md +114 -114
  13. data/Rakefile +29 -29
  14. data/cucumber.yml +8 -8
  15. data/lib/page-object.rb +431 -420
  16. data/lib/page-object/accessors.rb +1201 -1175
  17. data/lib/page-object/element_locators.rb +21 -21
  18. data/lib/page-object/elements.rb +62 -61
  19. data/lib/page-object/elements/area.rb +9 -9
  20. data/lib/page-object/elements/audio.rb +9 -9
  21. data/lib/page-object/elements/bold.rb +9 -9
  22. data/lib/page-object/elements/button.rb +12 -12
  23. data/lib/page-object/elements/canvas.rb +10 -10
  24. data/lib/page-object/elements/check_box.rb +9 -9
  25. data/lib/page-object/elements/date_field.rb +10 -0
  26. data/lib/page-object/elements/div.rb +9 -9
  27. data/lib/page-object/elements/element.rb +212 -159
  28. data/lib/page-object/elements/file_field.rb +9 -9
  29. data/lib/page-object/elements/form.rb +9 -9
  30. data/lib/page-object/elements/heading.rb +14 -14
  31. data/lib/page-object/elements/hidden_field.rb +9 -9
  32. data/lib/page-object/elements/image.rb +10 -10
  33. data/lib/page-object/elements/italic.rb +9 -9
  34. data/lib/page-object/elements/label.rb +9 -9
  35. data/lib/page-object/elements/link.rb +9 -9
  36. data/lib/page-object/elements/list_item.rb +9 -9
  37. data/lib/page-object/elements/media.rb +11 -11
  38. data/lib/page-object/elements/option.rb +9 -9
  39. data/lib/page-object/elements/ordered_list.rb +43 -45
  40. data/lib/page-object/elements/paragraph.rb +9 -9
  41. data/lib/page-object/elements/radio_button.rb +9 -9
  42. data/lib/page-object/elements/select_list.rb +42 -42
  43. data/lib/page-object/elements/span.rb +9 -9
  44. data/lib/page-object/elements/table.rb +85 -68
  45. data/lib/page-object/elements/table_cell.rb +10 -10
  46. data/lib/page-object/elements/table_row.rb +52 -52
  47. data/lib/page-object/elements/text_area.rb +9 -9
  48. data/lib/page-object/elements/text_field.rb +10 -10
  49. data/lib/page-object/elements/unordered_list.rb +42 -44
  50. data/lib/page-object/elements/video.rb +9 -9
  51. data/lib/page-object/indexed_properties.rb +41 -41
  52. data/lib/page-object/javascript/angularjs.rb +14 -14
  53. data/lib/page-object/javascript/jquery.rb +14 -14
  54. data/lib/page-object/javascript/prototype.rb +14 -14
  55. data/lib/page-object/javascript/yui.rb +18 -18
  56. data/lib/page-object/javascript_framework_facade.rb +80 -80
  57. data/lib/page-object/locator_generator.rb +183 -182
  58. data/lib/page-object/nested_elements.rb +17 -17
  59. data/lib/page-object/page_factory.rb +108 -108
  60. data/lib/page-object/page_populator.rb +105 -95
  61. data/lib/page-object/platforms/watir.rb +50 -50
  62. data/lib/page-object/platforms/watir/page_object.rb +1155 -1124
  63. data/lib/page-object/section_collection.rb +16 -16
  64. data/lib/page-object/version.rb +4 -4
  65. data/lib/page-object/widgets.rb +98 -98
  66. data/page-object.gemspec +32 -32
  67. metadata +12 -12
@@ -1,21 +1,21 @@
1
- require 'page-object/locator_generator'
2
-
3
- module PageObject
4
- module ElementLocators
5
-
6
- def self.included(cls)
7
- ::PageObject::LocatorGenerator.generate_locators(cls)
8
- end
9
-
10
- def element(tag, identifier={:index => 0})
11
- platform.element_for(tag, identifier.clone)
12
- end
13
-
14
- private
15
-
16
- def locator(identifier)
17
- identifier[0] ? identifier[0] : {:index => 0}
18
- end
19
-
20
- end
21
- end
1
+ require 'page-object/locator_generator'
2
+
3
+ module PageObject
4
+ module ElementLocators
5
+
6
+ def self.included(cls)
7
+ ::PageObject::LocatorGenerator.generate_locators(cls)
8
+ end
9
+
10
+ def element(tag, identifier={:index => 0})
11
+ platform.element_for(tag, identifier.clone)
12
+ end
13
+
14
+ private
15
+
16
+ def locator(identifier)
17
+ identifier[0] ? identifier[0] : {:index => 0}
18
+ end
19
+
20
+ end
21
+ end
@@ -1,61 +1,62 @@
1
- module PageObject
2
- module Elements
3
- class << self
4
-
5
- #
6
- # method to return the collection of tag_name to class mappings
7
- #
8
- def tag_to_class
9
- @tag_to_class ||= {}
10
- end
11
-
12
- def type_to_class
13
- @type_to_class ||= {}
14
- end
15
-
16
- #
17
- # method to return the element for a tag_name
18
- #
19
- def element_class_for(tag_name, type=nil)
20
- return type_to_class[type.to_sym] if type
21
- tag_to_class[tag_name.to_sym] || ::PageObject::Elements::Element
22
- end
23
-
24
- end
25
- end
26
- end
27
-
28
-
29
- require 'page-object/elements/element'
30
- require 'page-object/elements/link'
31
- require 'page-object/elements/text_field'
32
- require 'page-object/elements/select_list'
33
- require 'page-object/elements/check_box'
34
- require 'page-object/elements/button'
35
- require 'page-object/elements/radio_button'
36
- require 'page-object/elements/div'
37
- require 'page-object/elements/table'
38
- require 'page-object/elements/table_cell'
39
- require 'page-object/elements/table_row'
40
- require 'page-object/elements/span'
41
- require 'page-object/elements/image'
42
- require 'page-object/elements/hidden_field'
43
- require 'page-object/elements/form'
44
- require 'page-object/elements/text_area'
45
- require 'page-object/elements/list_item'
46
- require 'page-object/elements/unordered_list'
47
- require 'page-object/elements/ordered_list'
48
- require 'page-object/elements/option'
49
- require 'page-object/elements/heading'
50
- require 'page-object/elements/paragraph'
51
- require 'page-object/elements/label'
52
- require 'page-object/elements/file_field'
53
- require 'page-object/elements/area'
54
- require 'page-object/elements/canvas'
55
- require 'page-object/elements/media'
56
- require 'page-object/elements/audio'
57
- require 'page-object/elements/video'
58
- require 'page-object/elements/bold'
59
- require 'page-object/elements/italic'
60
-
61
-
1
+ module PageObject
2
+ module Elements
3
+ class << self
4
+
5
+ #
6
+ # method to return the collection of tag_name to class mappings
7
+ #
8
+ def tag_to_class
9
+ @tag_to_class ||= {}
10
+ end
11
+
12
+ def type_to_class
13
+ @type_to_class ||= {}
14
+ end
15
+
16
+ #
17
+ # method to return the element for a tag_name
18
+ #
19
+ def element_class_for(tag_name, type=nil)
20
+ return type_to_class[type.to_sym] if type
21
+ tag_to_class[tag_name.to_sym] || ::PageObject::Elements::Element
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ require 'page-object/elements/element'
30
+ require 'page-object/elements/link'
31
+ require 'page-object/elements/text_field'
32
+ require 'page-object/elements/date_field'
33
+ require 'page-object/elements/select_list'
34
+ require 'page-object/elements/check_box'
35
+ require 'page-object/elements/button'
36
+ require 'page-object/elements/radio_button'
37
+ require 'page-object/elements/div'
38
+ require 'page-object/elements/table'
39
+ require 'page-object/elements/table_cell'
40
+ require 'page-object/elements/table_row'
41
+ require 'page-object/elements/span'
42
+ require 'page-object/elements/image'
43
+ require 'page-object/elements/hidden_field'
44
+ require 'page-object/elements/form'
45
+ require 'page-object/elements/text_area'
46
+ require 'page-object/elements/list_item'
47
+ require 'page-object/elements/unordered_list'
48
+ require 'page-object/elements/ordered_list'
49
+ require 'page-object/elements/option'
50
+ require 'page-object/elements/heading'
51
+ require 'page-object/elements/paragraph'
52
+ require 'page-object/elements/label'
53
+ require 'page-object/elements/file_field'
54
+ require 'page-object/elements/area'
55
+ require 'page-object/elements/canvas'
56
+ require 'page-object/elements/media'
57
+ require 'page-object/elements/audio'
58
+ require 'page-object/elements/video'
59
+ require 'page-object/elements/bold'
60
+ require 'page-object/elements/italic'
61
+
62
+
@@ -1,9 +1,9 @@
1
- module PageObject
2
- module Elements
3
- class Area < Element
4
-
5
- end
6
-
7
- ::PageObject::Elements.type_to_class[:area] = ::PageObject::Elements::Area
8
- end
9
- end
1
+ module PageObject
2
+ module Elements
3
+ class Area < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.type_to_class[:area] = ::PageObject::Elements::Area
8
+ end
9
+ end
@@ -1,9 +1,9 @@
1
- module PageObject
2
- module Elements
3
- class Audio < Media
4
-
5
- end
6
-
7
- ::PageObject::Elements.type_to_class[:audio] = ::PageObject::Elements::Audio
8
- end
9
- end
1
+ module PageObject
2
+ module Elements
3
+ class Audio < Media
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.type_to_class[:audio] = ::PageObject::Elements::Audio
8
+ end
9
+ end
@@ -1,9 +1,9 @@
1
- module PageObject
2
- module Elements
3
- class Bold < Element
4
-
5
- end
6
-
7
- ::PageObject::Elements.tag_to_class[:b] = ::PageObject::Elements::Bold
8
- end
9
- end
1
+ module PageObject
2
+ module Elements
3
+ class Bold < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.tag_to_class[:b] = ::PageObject::Elements::Bold
8
+ end
9
+ end
@@ -1,12 +1,12 @@
1
- module PageObject
2
- module Elements
3
- class Button < Element
4
-
5
- end
6
-
7
- ::PageObject::Elements.type_to_class[:submit] = ::PageObject::Elements::Button
8
- ::PageObject::Elements.type_to_class[:image] = ::PageObject::Elements::Button
9
- ::PageObject::Elements.type_to_class[:button] = ::PageObject::Elements::Button
10
- ::PageObject::Elements.type_to_class[:reset] = ::PageObject::Elements::Button
11
- end
12
- end
1
+ module PageObject
2
+ module Elements
3
+ class Button < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.type_to_class[:submit] = ::PageObject::Elements::Button
8
+ ::PageObject::Elements.type_to_class[:image] = ::PageObject::Elements::Button
9
+ ::PageObject::Elements.type_to_class[:button] = ::PageObject::Elements::Button
10
+ ::PageObject::Elements.type_to_class[:reset] = ::PageObject::Elements::Button
11
+ end
12
+ end
@@ -1,10 +1,10 @@
1
- module PageObject
2
- module Elements
3
- class Canvas < Element
4
-
5
- end
6
-
7
- ::PageObject::Elements.type_to_class[:canvas] = ::PageObject::Elements::Canvas
8
- end
9
- end
10
-
1
+ module PageObject
2
+ module Elements
3
+ class Canvas < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.type_to_class[:canvas] = ::PageObject::Elements::Canvas
8
+ end
9
+ end
10
+
@@ -1,9 +1,9 @@
1
- module PageObject
2
- module Elements
3
- class CheckBox < Element
4
-
5
- end
6
-
7
- ::PageObject::Elements.type_to_class[:checkbox] = ::PageObject::Elements::CheckBox
8
- end
9
- end
1
+ module PageObject
2
+ module Elements
3
+ class CheckBox < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.type_to_class[:checkbox] = ::PageObject::Elements::CheckBox
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module PageObject
2
+ module Elements
3
+ class DateField < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.type_to_class[:date] = ::PageObject::Elements::DateField
8
+ end
9
+ end
10
+
@@ -1,9 +1,9 @@
1
- module PageObject
2
- module Elements
3
- class Div < Element
4
-
5
- end
6
-
7
- ::PageObject::Elements.tag_to_class[:div] = ::PageObject::Elements::Div
8
- end
9
- end
1
+ module PageObject
2
+ module Elements
3
+ class Div < Element
4
+
5
+ end
6
+
7
+ ::PageObject::Elements.tag_to_class[:div] = ::PageObject::Elements::Div
8
+ end
9
+ end
@@ -1,159 +1,212 @@
1
- require 'page-object/nested_elements'
2
- require 'watir/extensions/select_text'
3
-
4
- module PageObject
5
- module Elements
6
- #
7
- # Contains functionality that is common across all elements.
8
- #
9
- # @see PageObject::Platforms::Watir::Element for the Watir version of all common methods
10
- #
11
- class Element
12
- include ::PageObject::NestedElements
13
-
14
- attr_reader :element
15
-
16
- def initialize(element)
17
- @element = element
18
- @platform = PageObject::Platforms::Watir::PageObject.new(@element)
19
- end
20
-
21
- #
22
- # return true if the element is not enabled
23
- #
24
- def disabled?
25
- not enabled?
26
- end
27
-
28
- #
29
- # specify plural form of element
30
- #
31
- def self.plural_form
32
- "#{self.to_s.split('::')[-1].
33
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
34
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
35
- tr("-", "_").
36
- downcase}s"
37
- end
38
-
39
- #
40
- # Keeps checking until the element is visible
41
- #
42
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
43
- #
44
- def check_visible(timeout=::PageObject.default_element_wait)
45
- timed_loop(timeout) do |element|
46
- element.visible?
47
- end
48
- end
49
-
50
- #
51
- # Keeps checking until the element exists
52
- #
53
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
54
- #
55
- def check_exists(timeout=::PageObject.default_element_wait)
56
- timed_loop(timeout) do |element|
57
- element.exists?
58
- end
59
- end
60
-
61
- #
62
- # compare this element to another to determine if they are equal
63
- #
64
- def ==(other)
65
- other.is_a? self.class and element == other.element
66
- end
67
-
68
- #
69
- # find the parent element
70
- #
71
- def parent(opt = {})
72
- parent = element.parent(opt)
73
- type = element.type if parent.tag_name.to_sym == :input
74
- cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
75
- cls.new(parent.to_subtype)
76
- end
77
-
78
- #
79
- # Waits until the element is present
80
- #
81
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
82
- #
83
- def when_present(timeout=::PageObject.default_element_wait)
84
- element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?)
85
- self
86
- end
87
-
88
- #
89
- # Waits until the element is not present
90
- #
91
- # @param [Integer] (defaults to: 5) seconds to wait before
92
- # timing out
93
- #
94
- def when_not_present(timeout=::PageObject.default_element_wait)
95
- element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?)
96
- end
97
-
98
- #
99
- # Waits until the element is visible
100
- #
101
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
102
- #
103
- def when_visible(timeout=::PageObject.default_element_wait)
104
- when_present(timeout)
105
- element.wait_until(timeout: timeout, message: "Element not visible in #{timeout} seconds", &:visible?)
106
- self
107
- end
108
-
109
- #
110
- # Waits until the element is not visible
111
- #
112
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
113
- #
114
- def when_not_visible(timeout=::PageObject.default_element_wait)
115
- when_present(timeout)
116
- element.wait_while(timeout: timeout, message: "Element still visible after #{timeout} seconds", &:visible?)
117
- end
118
-
119
- #
120
- # Waits until the block returns true
121
- #
122
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
123
- # @param [String] the message to display if the event timeouts
124
- # @param the block to execute when the event occurs
125
- #
126
- def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block)
127
- element.wait_until(timeout: timeout, message: message, &block)
128
- end
129
-
130
- def name
131
- element.attribute(:name)
132
- end
133
-
134
- # @private
135
- # delegate calls to driver element
136
- def method_missing(*args, &block)
137
- m = args.shift
138
- element.send m, *args, &block
139
- end
140
-
141
- def respond_to_missing?(m,*args)
142
- element.respond_to?(m) || super
143
- end
144
-
145
- private
146
-
147
- def timed_loop(timeout)
148
- end_time = ::Time.now + timeout
149
- until ::Time.now > end_time
150
- result = yield(self)
151
- return result if result
152
- sleep 0.5
153
- end
154
- false
155
- end
156
-
157
- end
158
- end
159
- end
1
+ require 'page-object/nested_elements'
2
+
3
+ module PageObject
4
+ module Elements
5
+ #
6
+ # Contains functionality that is common across all elements.
7
+ #
8
+ # @see PageObject::Platforms::Watir::Element for the Watir version of all common methods
9
+ #
10
+ class Element
11
+ include ::PageObject::NestedElements
12
+
13
+ attr_reader :element
14
+
15
+ def initialize(element)
16
+ @element = element
17
+ @platform = PageObject::Platforms::Watir::PageObject.new(@element)
18
+ end
19
+
20
+ #
21
+ # return true if the element is not enabled
22
+ #
23
+ def disabled?
24
+ not enabled?
25
+ end
26
+
27
+ #
28
+ # return true if the element exists and is visible
29
+ #
30
+ def present?
31
+ element.present?
32
+ end
33
+
34
+ def drag_and_drop_on(droppable)
35
+ droppable_native = droppable.kind_of?(PageObject::Elements::Element) ? droppable.element : droppable
36
+ element.drag_and_drop_on(droppable_native)
37
+ end
38
+
39
+ #
40
+ # specify plural form of element
41
+ #
42
+ def self.plural_form
43
+ "#{self.to_s.split('::')[-1].
44
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
45
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
46
+ tr("-", "_").
47
+ downcase}s"
48
+ end
49
+
50
+ #
51
+ # Keeps checking until the element is visible
52
+ #
53
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
54
+ #
55
+ def check_visible(timeout=::PageObject.default_element_wait)
56
+ timed_loop(timeout) do |element|
57
+ element.present?
58
+ end
59
+ end
60
+
61
+ #
62
+ # Keeps checking until the element exists
63
+ #
64
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
65
+ #
66
+ def check_exists(timeout=::PageObject.default_element_wait)
67
+ timed_loop(timeout) do |element|
68
+ element.exists?
69
+ end
70
+ end
71
+
72
+ #
73
+ # compare this element to another to determine if they are equal
74
+ #
75
+ def ==(other)
76
+ other.is_a? self.class and element == other.element
77
+ end
78
+
79
+ #
80
+ # find the parent element
81
+ #
82
+ def parent(opt = {})
83
+ parent = element.parent(opt)
84
+ pageobject_wrapper(parent)
85
+ end
86
+
87
+ #
88
+ # Return the element that exists at the same level of the DOM
89
+ # immediately prior to this element
90
+ #
91
+ def preceding_sibling(opt = {})
92
+ sibling = element.preceding_sibling(opt)
93
+ pageobject_wrapper(sibling)
94
+ end
95
+
96
+ #
97
+ # Return the element that exists at the same level of the DOM
98
+ # immediately after this element
99
+ #
100
+ def following_sibling(opt={})
101
+ sibling = element.following_sibling(opt)
102
+ pageobject_wrapper(sibling)
103
+ end
104
+
105
+ #
106
+ # Return all elements that are direct children of this element's parent
107
+ #
108
+ def siblings(opt={})
109
+ siblings = element.siblings(opt)
110
+ siblings.collect {|sibling| pageobject_wrapper(sibling)}
111
+ end
112
+
113
+ #
114
+ # Return all elements that are children of this element
115
+ #
116
+ def children(opt={})
117
+ children = element.children(opt)
118
+ children.collect {|child| pageobject_wrapper(child)}
119
+ end
120
+
121
+ #
122
+ # Return all elements that exist at the same level of the DOM
123
+ # immediately prior to this element
124
+ #
125
+ def preceding_siblings(opt={})
126
+ siblings = element.preceding_siblings(opt)
127
+ siblings.collect {|sibling| pageobject_wrapper(sibling)}
128
+ end
129
+
130
+ #
131
+ # Return all elements that exist at the same level of the DOM
132
+ # immediately after this element
133
+ #
134
+ def following_siblings(opt={})
135
+ siblings = element.following_siblings(opt)
136
+ siblings.collect {|sibling| pageobject_wrapper(sibling)}
137
+ end
138
+
139
+ #
140
+ # Waits until the element is present
141
+ #
142
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
143
+ #
144
+ def when_present(timeout=::PageObject.default_element_wait)
145
+ element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?)
146
+ self
147
+ end
148
+ alias_method :when_visible, :when_present
149
+
150
+ #
151
+ # Waits until the element is not present
152
+ #
153
+ # @param [Integer] (defaults to: 5) seconds to wait before
154
+ # timing out
155
+ #
156
+ def when_not_present(timeout=::PageObject.default_element_wait)
157
+ element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?)
158
+ end
159
+ alias_method :when_not_visible, :when_not_present
160
+
161
+ #
162
+ # Waits until the block returns true
163
+ #
164
+ # @param [Integer] (defaults to: 5) seconds to wait before timing out
165
+ # @param [String] the message to display if the event timeouts
166
+ # @param the block to execute when the event occurs
167
+ #
168
+ def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block)
169
+ element.wait_until(timeout: timeout, message: message, &block)
170
+ end
171
+
172
+ def name
173
+ element.attribute(:name)
174
+ end
175
+
176
+ # @private
177
+ # delegate calls to driver element
178
+ def method_missing(method, *args, &block)
179
+ if element.respond_to?(method)
180
+ element.send(method, *args, &block)
181
+ else
182
+ super
183
+ end
184
+ end
185
+
186
+ def respond_to_missing?(m,*args)
187
+ element.respond_to?(m) || super
188
+ end
189
+
190
+ protected
191
+
192
+ def pageobject_wrapper(watir_object)
193
+ type = element.type if watir_object.tag_name.to_sym == :input
194
+ cls = ::PageObject::Elements.element_class_for(watir_object.tag_name, type)
195
+ cls.new(watir_object.to_subtype)
196
+ end
197
+
198
+ private
199
+
200
+ def timed_loop(timeout)
201
+ end_time = ::Time.now + timeout
202
+ until ::Time.now > end_time
203
+ result = yield(self)
204
+ return result if result
205
+ sleep 0.5
206
+ end
207
+ false
208
+ end
209
+
210
+ end
211
+ end
212
+ end