page-object 2.0.0 → 2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/ChangeLog +10 -0
  4. data/README.md +12 -0
  5. data/Rakefile +2 -12
  6. data/cucumber.yml +2 -4
  7. data/lib/page-object.rb +12 -20
  8. data/lib/page-object/accessors.rb +50 -363
  9. data/lib/page-object/elements/bold.rb +0 -1
  10. data/lib/page-object/elements/button.rb +0 -4
  11. data/lib/page-object/elements/check_box.rb +19 -7
  12. data/lib/page-object/elements/div.rb +0 -4
  13. data/lib/page-object/elements/element.rb +159 -90
  14. data/lib/page-object/elements/file_field.rb +5 -7
  15. data/lib/page-object/elements/form.rb +0 -8
  16. data/lib/page-object/elements/hidden_field.rb +1 -4
  17. data/lib/page-object/elements/image.rb +13 -7
  18. data/lib/page-object/elements/label.rb +0 -4
  19. data/lib/page-object/elements/link.rb +0 -13
  20. data/lib/page-object/elements/list_item.rb +0 -3
  21. data/lib/page-object/elements/ordered_list.rb +30 -5
  22. data/lib/page-object/elements/radio_button.rb +12 -7
  23. data/lib/page-object/elements/select_list.rb +40 -8
  24. data/lib/page-object/elements/span.rb +0 -3
  25. data/lib/page-object/elements/table.rb +26 -5
  26. data/lib/page-object/elements/table_cell.rb +0 -4
  27. data/lib/page-object/elements/table_row.rb +30 -5
  28. data/lib/page-object/elements/text_area.rb +7 -7
  29. data/lib/page-object/elements/text_field.rb +5 -11
  30. data/lib/page-object/elements/unordered_list.rb +30 -5
  31. data/lib/page-object/indexed_properties.rb +1 -0
  32. data/lib/page-object/platforms.rb +0 -1
  33. data/lib/page-object/platforms/watir.rb +26 -4
  34. data/lib/page-object/platforms/watir/page_object.rb +4 -4
  35. data/lib/page-object/version.rb +1 -1
  36. data/lib/page-object/widgets.rb +0 -1
  37. data/page-object.gemspec +1 -15
  38. metadata +5 -47
  39. data/lib/page-object/platforms/selenium_webdriver.rb +0 -30
  40. data/lib/page-object/platforms/selenium_webdriver/button.rb +0 -15
  41. data/lib/page-object/platforms/selenium_webdriver/check_box.rb +0 -29
  42. data/lib/page-object/platforms/selenium_webdriver/element.rb +0 -335
  43. data/lib/page-object/platforms/selenium_webdriver/file_field.rb +0 -16
  44. data/lib/page-object/platforms/selenium_webdriver/form.rb +0 -16
  45. data/lib/page-object/platforms/selenium_webdriver/image.rb +0 -28
  46. data/lib/page-object/platforms/selenium_webdriver/link.rb +0 -23
  47. data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +0 -41
  48. data/lib/page-object/platforms/selenium_webdriver/page_object.rb +0 -1297
  49. data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +0 -22
  50. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +0 -93
  51. data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +0 -42
  52. data/lib/page-object/platforms/selenium_webdriver/table.rb +0 -42
  53. data/lib/page-object/platforms/selenium_webdriver/table_row.rb +0 -43
  54. data/lib/page-object/platforms/selenium_webdriver/text_area.rb +0 -17
  55. data/lib/page-object/platforms/selenium_webdriver/text_field.rb +0 -17
  56. data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +0 -37
  57. data/lib/page-object/platforms/watir/check_box.rb +0 -29
  58. data/lib/page-object/platforms/watir/element.rb +0 -295
  59. data/lib/page-object/platforms/watir/file_field.rb +0 -16
  60. data/lib/page-object/platforms/watir/form.rb +0 -16
  61. data/lib/page-object/platforms/watir/image.rb +0 -22
  62. data/lib/page-object/platforms/watir/link.rb +0 -15
  63. data/lib/page-object/platforms/watir/ordered_list.rb +0 -40
  64. data/lib/page-object/platforms/watir/radio_button.rb +0 -22
  65. data/lib/page-object/platforms/watir/select_list.rb +0 -74
  66. data/lib/page-object/platforms/watir/table.rb +0 -38
  67. data/lib/page-object/platforms/watir/table_row.rb +0 -37
  68. data/lib/page-object/platforms/watir/text_area.rb +0 -23
  69. data/lib/page-object/platforms/watir/text_field.rb +0 -16
  70. data/lib/page-object/platforms/watir/unordered_list.rb +0 -42
@@ -1,22 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
- module RadioButton
5
-
6
- #
7
- # select the radiobutton
8
- #
9
- def select
10
- element.click unless selected?
11
- end
12
-
13
- #
14
- # return if it is selected
15
- #
16
- def selected?
17
- element.selected?
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,93 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
- module SelectList
5
-
6
- #
7
- # Return the PageObject::Elements::Option for the index provided. Index
8
- # is zero based.
9
- #
10
- # @return [PageObject::Elements::Option]
11
- #
12
- def [](idx)
13
- options[idx]
14
- end
15
-
16
- #
17
- # Select a value from the list
18
- #
19
- def select(value)
20
- find_options.find do |option|
21
- option.text == value
22
- end.click
23
- end
24
-
25
- #
26
- # Select the option(s) whose value attribute matches the given
27
- # string
28
- #
29
- def select_value(value)
30
- options = find_options.find_all do |option|
31
- option.attribute('value') == value
32
- end
33
- options.each {|opt| opt.click}
34
- end
35
-
36
- #
37
- # Return an array of Options contained in the select list.
38
- #
39
- # @return [array of PageObject::Elements::Option]
40
- def options
41
- find_options.map { |e| ::PageObject::Elements::Option.new(e, :platform => @platform.class::PLATFORM_NAME) }
42
- end
43
-
44
- #
45
- # @return [Array<String>] An array of strings representing the text of the currently selected options.
46
- #
47
- def selected_options
48
- find_options.map { |e| e.text if e.selected? }.compact
49
- end
50
-
51
- #
52
- # @return [Array<String>] An array of strings representing the value of the currently selected options.
53
- #
54
- def selected_values
55
- find_options.map { |e| e.attribute('value') if e.selected? }.compact
56
- end
57
-
58
- #
59
- # Returns true if the select list has one or more options where text or label matches the given value.
60
- #
61
- # @param [String, Regexp] value A value.
62
- # @return [Boolean]
63
- def include?(value)
64
- find_options.any? { |e| e.text == value }
65
- end
66
-
67
- #
68
- # Returns true if any of the selected options' text match the given value.
69
- #
70
- # @param [String, Regexp] value A value.
71
- # @return [Boolean]
72
- def selected?(value)
73
- selected = find_options.select { |e| e if e.selected? }
74
- selected.any? { |e| e.text == value }
75
- end
76
-
77
- #
78
- # Deselect all selected options.
79
- #
80
- def clear
81
- find_options.select { |e| e.selected? }.each { |o| o.click }
82
- end
83
-
84
- private
85
-
86
- def find_options
87
- element.find_elements(:xpath, child_xpath)
88
- end
89
- end
90
- end
91
- end
92
-
93
- end
@@ -1,42 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
- class SurrogateSeleniumElement
5
- attr_accessor :identifier, :type, :tag, :other, :platform
6
-
7
- def exists?
8
- attempt_to_find_element unless @element
9
- @element ? (not @element.element.nil?) : false
10
- end
11
-
12
- def visible?
13
- attempt_to_find_element unless @element
14
- @element ? @element.element.displayed? : false
15
- end
16
-
17
- def nil?
18
- attempt_to_find_element unless @element
19
- @element ? @element.element.nil? : true
20
- end
21
-
22
- def displayed?
23
- attempt_to_find_element unless @element
24
- @element ? @element.element.displayed? : false
25
- end
26
-
27
- def method_missing(meth, *args)
28
- return @element.send(meth, *args) if @element
29
- $stderr.puts "You are calling #{meth} on an element that does not yet exist."
30
- raise Selenium::WebDriver::Error::NoSuchElementError
31
- end
32
-
33
- private
34
-
35
- def attempt_to_find_element
36
- @element = platform.send(:find_selenium_element, identifier, type, tag, other) unless @element
37
- @element = nil if @element.element.instance_of?(::PageObject::Platforms::SeleniumWebDriver::SurrogateSeleniumElement)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,42 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
- module Table
5
-
6
- #
7
- # Return the PageObject::Elements::TableRow for the index provided. Index
8
- # is zero based. If the index provided is a String then it
9
- # will be matched with the text from any column. The text can be a substring of the full column text.
10
- #
11
- # @return [PageObject::Elements::TableRow]
12
- #
13
- def [](idx)
14
- eles = table_rows
15
- idx = find_index_by_title(idx, eles) if idx.kind_of?(String)
16
- return nil unless idx
17
- initialize_row(eles[idx], :platform => @platform.class::PLATFORM_NAME)
18
- end
19
-
20
- #
21
- # Returns the number of rows in the table.
22
- #
23
- def rows
24
- table_rows.size
25
- end
26
-
27
- private
28
-
29
- def find_index_by_title(row_title, eles)
30
- eles.find_index do |row|
31
- columns = row.find_elements(:xpath, ".//child::td|th")
32
- columns.any? { |col| col.text.include? row_title }
33
- end
34
- end
35
-
36
- def table_rows
37
- element.find_elements(:xpath, child_xpath)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,43 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
-
5
- module TableRow
6
-
7
- #
8
- # Return the PageObject::Elements::TableCell for the index provided. Index
9
- # is zero based. If the index provided is a String then it
10
- # will be matched with the text from the columns in the first row.
11
- # The text can be a substring of the full column text.
12
- #
13
- def [](idx)
14
- els = table_cells
15
- idx = find_index_by_title(idx) if idx.kind_of?(String)
16
- return nil unless idx && columns >= idx + 1
17
- initialize_cell(els[idx], :platform => @platform.class::PLATFORM_NAME)
18
- end
19
-
20
- #
21
- # Returns the number of columns in the table.
22
- #
23
- def columns
24
- table_cells.size
25
- end
26
-
27
- private
28
-
29
- def find_index_by_title(title)
30
- table = parent
31
- parent_tag_name = parent.element.tag_name
32
- table = table.parent if (parent_tag_name == 'tbody' || parent_tag_name == 'thead')
33
- table[0].find_index { |column| column.text.include? title }
34
- end
35
-
36
- def table_cells
37
- element.find_elements(:xpath, child_xpath)
38
- end
39
-
40
- end
41
- end
42
- end
43
- end
@@ -1,17 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
-
5
- module TextArea
6
-
7
- #
8
- # Set the value of the TextArea
9
- #
10
- def value=(new_value)
11
- element.clear
12
- element.send_keys(new_value)
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
-
5
- module TextField
6
-
7
- #
8
- # Set the value of the TextField
9
- #
10
- def value=(new_value)
11
- element.clear
12
- element.send_keys(new_value)
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,37 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module SeleniumWebDriver
4
- module UnorderedList
5
-
6
- #
7
- # Return the PageObject::Elements::ListItem for the index provided. Index
8
- # is zero based.
9
- #
10
- # @return [PageObject::Elements::ListItem]
11
- #
12
- def [](idx)
13
- Object::PageObject::Elements::ListItem.new(children[idx], :platform => :selenium_webdriver)
14
- end
15
-
16
- #
17
- # Return the number of items contained in the unordered list
18
- #
19
- def items
20
- children.size
21
- end
22
-
23
- def list_items
24
- children.collect do |obj|
25
- Object::PageObject::Elements::ListItem.new(obj, :platform => :selenium_webdriver)
26
- end
27
- end
28
-
29
- private
30
-
31
- def children
32
- element.find_elements(:xpath, child_xpath)
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,29 +0,0 @@
1
- module PageObject
2
- module Platforms
3
- module WatirWebDriver
4
- module CheckBox
5
-
6
- #
7
- # check the checkbox
8
- #
9
- def check
10
- element.set
11
- end
12
-
13
- #
14
- # uncheck the checkbox
15
- #
16
- def uncheck
17
- element.clear
18
- end
19
-
20
- #
21
- # return true if checkbox is checked
22
- #
23
- def checked?
24
- element.set?
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,295 +0,0 @@
1
- require 'watir/extensions/select_text'
2
-
3
- module PageObject
4
- module Platforms
5
- #
6
- # Watir implementation of the common functionality found across all elements
7
- #
8
- module WatirWebDriver
9
- module Element
10
-
11
- #
12
- # return true if an element is visible
13
- #
14
- def visible?
15
- element.present?
16
- end
17
-
18
- #
19
- # return true if an element exists
20
- #
21
- def exists?
22
- element.exists?
23
- end
24
-
25
- #
26
- # flash the element by temporarily changing the background color
27
- #
28
- def flash
29
- element.flash
30
- end
31
-
32
- #
33
- # Get the text for the element
34
- #
35
- # @return [String]
36
- #
37
- def text
38
- element.text
39
- end
40
-
41
- #
42
- # Get the html for the element
43
- #
44
- # @return [String]
45
- #
46
- def html
47
- element.html
48
- end
49
-
50
- #
51
- # Get the value of this element
52
- #
53
- # @return [String]
54
- #
55
- def value
56
- element.value
57
- end
58
-
59
- #
60
- # compare this element to another to determine if they are equal
61
- #
62
- def ==(other)
63
- other.is_a? self.class and element == other.element
64
- end
65
-
66
- #
67
- # Get the tag name of this element
68
- #
69
- # @return [String]
70
- #
71
- def tag_name
72
- element.tag_name
73
- end
74
-
75
- #
76
- # Get the value of a the given attribute of the element. Will
77
- # return the current value, even if this has been modified
78
- # after the page has been loaded. More exactly, this method
79
- # will return the value of the given attribute, unless that
80
- # attribute is not present, in which case the value of the
81
- # property with the same name is returned. If neither value is
82
- # set, nil is returned. The "style" attribute is converted as
83
- # best can be to a text representation with a trailing
84
- # semi-colon. The following are deemed to be "boolean"
85
- # attributes, and will return either "true" or "false":
86
- #
87
- # async, autofocus, autoplay, checked, compact, complete,
88
- # controls, declare, defaultchecked, defaultselected, defer,
89
- # disabled, draggable, ended, formnovalidate, hidden, indeterminate,
90
- # iscontenteditable, ismap, itemscope, loop, multiple, muted,
91
- # nohref, noresize, noshade, novalidate, nowrap, open, paused,
92
- # pubdate, readonly, required, reversed, scoped, seamless, seeking,
93
- # selected, spellcheck, truespeed, willvalidate
94
- #
95
- # Finally, the following commonly mis-capitalized
96
- # attribute/property names are evaluated as expected:
97
- #
98
- # class, readonly
99
- #
100
- # @param [String]
101
- # attribute name
102
- # @return [String,nil]
103
- # attribute value
104
- #
105
- def attribute(attribute_name)
106
- element.attribute_value attribute_name
107
- end
108
-
109
- #
110
- # Fire the provided event on the current element
111
- #
112
- def fire_event(event_name)
113
- element.fire_event(event_name)
114
- end
115
-
116
- #
117
- # hover over the element
118
- #
119
- def hover
120
- element.hover
121
- end
122
-
123
- #
124
- # double click the element
125
- #
126
- def double_click
127
- element.double_click
128
- end
129
-
130
- #
131
- # find the parent element
132
- #
133
- def parent
134
- parent = element.parent
135
- type = element.type if parent.tag_name.to_sym == :input
136
- cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
137
- cls.new(parent, :platform => @platform.class::PLATFORM_NAME)
138
- end
139
-
140
- #
141
- # Set the focus to the current element
142
- #
143
- def focus
144
- element.focus
145
- end
146
-
147
- #
148
- # return true if an element is focused
149
- #
150
- def focused?
151
- element.focused?
152
- end
153
-
154
- #
155
- # Select the provided text
156
- #
157
- def select_text(text)
158
- element.select_text text
159
- end
160
-
161
- #
162
- # Right click on an element
163
- #
164
- def right_click
165
- element.right_click
166
- end
167
-
168
- #
169
- # Waits until the element is present
170
- #
171
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
172
- #
173
- def when_present(timeout=::PageObject.default_element_wait)
174
- element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?)
175
- self
176
- end
177
-
178
- #
179
- # Waits until the element is not present
180
- #
181
- # @param [Integer] (defaults to: 5) seconds to wait before
182
- # timing out
183
- #
184
- def when_not_present(timeout=::PageObject.default_element_wait)
185
- element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?)
186
- end
187
-
188
- #
189
- # Waits until the element is visible
190
- #
191
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
192
- #
193
- def when_visible(timeout=::PageObject.default_element_wait)
194
- element.wait_until(timeout: timeout, message: "Element not visible in #{timeout} seconds", &:visible?)
195
- self
196
- end
197
-
198
- #
199
- # Waits until the element is not visible
200
- #
201
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
202
- #
203
- def when_not_visible(timeout=::PageObject.default_element_wait)
204
- element.wait_while(timeout: timeout, message: "Element still visible after #{timeout} seconds", &:visible?)
205
- end
206
-
207
- #
208
- # Waits until the block returns true
209
- #
210
- # @param [Integer] (defaults to: 5) seconds to wait before timing out
211
- # @param [String] the message to display if the event timeouts
212
- # @param the block to execute when the event occurs
213
- #
214
- def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block)
215
- Object::Watir::Wait.until(timeout: timeout, message: message, &block)
216
- end
217
-
218
- #
219
- # Send keystrokes to this element
220
- #
221
- # @param [String, Symbol, Array]
222
- #
223
- # Examples:
224
- #
225
- # element.send_keys "foo" #=> value: 'foo'
226
- # element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
227
- # element.send_keys [:control, 'a'], :space #=> value: ' '
228
- #
229
- # @see Selenium::WebDriver::Keys::KEYS
230
- #
231
- def send_keys(*args)
232
- element.send_keys(*args)
233
- end
234
-
235
- #
236
- # clear the contents of the element
237
- #
238
- def clear
239
- element.clear
240
- end
241
-
242
- #
243
- # get the id of the element
244
- #
245
- def id
246
- element.id
247
- end
248
-
249
- #
250
- # Scroll until the element is viewable
251
- #
252
- def scroll_into_view
253
- element.wd.location_once_scrolled_into_view
254
- end
255
-
256
- #
257
- # location of element (x, y)
258
- #
259
- def location
260
- element.wd.location
261
- end
262
-
263
- #
264
- # size of element (width, height)
265
- #
266
- def size
267
- element.wd.size
268
- end
269
-
270
- #
271
- # Get height of element
272
- #
273
- def height
274
- element.wd.size['height']
275
- end
276
-
277
- #
278
- # Get width of element
279
- #
280
- def width
281
- element.wd.size['width']
282
- end
283
-
284
- #
285
- # Get centre coordinates of element
286
- #
287
- def centre
288
- location = element.wd.location
289
- size = element.wd.size
290
- {'y' => (location['y'] + (size['height']/2)), 'x' => (location['x'] + (size['width']/2))}
291
- end
292
- end
293
- end
294
- end
295
- end