testcentricity_web 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -11
  3. data/LICENSE.md +1 -1
  4. data/README.md +1931 -801
  5. data/lib/devices/devices.yml +144 -216
  6. data/lib/testcentricity_web/browser_helper.rb +33 -4
  7. data/lib/testcentricity_web/data_objects/environment.rb +96 -15
  8. data/lib/testcentricity_web/exception_queue_helper.rb +5 -6
  9. data/lib/testcentricity_web/version.rb +1 -1
  10. data/lib/testcentricity_web/web_core/page_object.rb +53 -49
  11. data/lib/testcentricity_web/web_core/page_objects_helper.rb +20 -11
  12. data/lib/testcentricity_web/web_core/page_section.rb +31 -34
  13. data/lib/testcentricity_web/web_core/webdriver_helper.rb +416 -288
  14. data/lib/testcentricity_web/web_elements/audio.rb +6 -4
  15. data/lib/testcentricity_web/web_elements/button.rb +7 -4
  16. data/lib/testcentricity_web/web_elements/checkbox.rb +149 -147
  17. data/lib/testcentricity_web/web_elements/file_field.rb +38 -36
  18. data/lib/testcentricity_web/web_elements/image.rb +75 -70
  19. data/lib/testcentricity_web/web_elements/label.rb +6 -4
  20. data/lib/testcentricity_web/web_elements/link.rb +15 -13
  21. data/lib/testcentricity_web/web_elements/list.rb +171 -169
  22. data/lib/testcentricity_web/web_elements/media.rb +384 -379
  23. data/lib/testcentricity_web/web_elements/radio.rb +135 -133
  24. data/lib/testcentricity_web/web_elements/range.rb +16 -29
  25. data/lib/testcentricity_web/web_elements/select_list.rb +247 -245
  26. data/lib/testcentricity_web/web_elements/table.rb +575 -573
  27. data/lib/testcentricity_web/web_elements/textfield.rb +143 -139
  28. data/lib/testcentricity_web/web_elements/ui_element.rb +1171 -0
  29. data/lib/testcentricity_web/web_elements/video.rb +39 -37
  30. data/lib/testcentricity_web/world_extensions.rb +37 -4
  31. data/lib/testcentricity_web.rb +4 -23
  32. metadata +27 -79
  33. data/lib/testcentricity_web/web_elements/ui_elements_helper.rb +0 -1148
@@ -1,195 +1,197 @@
1
1
  module TestCentricity
2
- class List < UIElement
3
- attr_accessor :list_item
4
- attr_accessor :selected_item
5
-
6
- def initialize(name, parent, locator, context)
7
- super
8
- @type = :list
9
- list_spec = {
10
- selected_item: 'li.selected',
11
- list_item: 'li'
12
- }
13
- define_list_elements(list_spec)
14
- end
2
+ module Elements
3
+ class List < UIElement
4
+ attr_accessor :list_item
5
+ attr_accessor :selected_item
6
+
7
+ def initialize(name, parent, locator, context)
8
+ super
9
+ @type = :list
10
+ list_spec = {
11
+ selected_item: 'li.selected',
12
+ list_item: 'li'
13
+ }
14
+ define_list_elements(list_spec)
15
+ end
15
16
 
16
- def define_list_elements(element_spec)
17
- element_spec.each do |element, value|
18
- case element
19
- when :list_item
20
- @list_item = value
21
- when :selected_item
22
- @selected_item = value
23
- else
24
- raise "#{element} is not a recognized list element"
17
+ def define_list_elements(element_spec)
18
+ element_spec.each do |element, value|
19
+ case element
20
+ when :list_item
21
+ @list_item = value
22
+ when :selected_item
23
+ @selected_item = value
24
+ else
25
+ raise "#{element} is not a recognized list element"
26
+ end
25
27
  end
26
28
  end
27
- end
28
29
 
29
- # Select the specified item in a list object. Accepts a String or Integer.
30
- #
31
- # @param item [String, Integer] text or index of item to select
32
- #
33
- # @example
34
- # province_list.choose_item(2)
35
- # province_list.choose_item('Manitoba')
36
- #
37
- def choose_item(item)
38
- obj, = find_element
39
- object_not_found_exception(obj, nil)
40
- if item.is_a?(Integer)
41
- obj.find(:css, "#{@list_item}:nth-of-type(#{item})", visible: true, minimum: 0, wait: 2).click
42
- elsif item.is_a?(String)
43
- items = obj.all(@list_item).collect(&:text)
44
- sleep(2) unless items.include?(item)
45
- obj.first(:css, @list_item, text: item).click
30
+ # Select the specified item in a list object. Accepts a String or Integer.
31
+ #
32
+ # @param item [String, Integer] text or index of item to select
33
+ #
34
+ # @example
35
+ # province_list.choose_item(2)
36
+ # province_list.choose_item('Manitoba')
37
+ #
38
+ def choose_item(item)
39
+ obj, = find_element
40
+ object_not_found_exception(obj, nil)
41
+ if item.is_a?(Integer)
42
+ obj.find(:css, "#{@list_item}:nth-of-type(#{item})", visible: true, wait: 2).click
43
+ elsif item.is_a?(String)
44
+ items = obj.all(@list_item).collect(&:text)
45
+ sleep(2) unless items.include?(item)
46
+ obj.first(:css, @list_item, text: item).click
47
+ end
46
48
  end
47
- end
48
49
 
49
- # Hover over the specified item in a list object. Accepts a String or Integer.
50
- #
51
- # @param item [String, Integer] text or index of item to hover over
52
- # @example
53
- # province_list.hover_item(2)
54
- # province_list.hover_item('Manitoba')
55
- #
56
- def hover_item(item)
57
- obj, = find_element
58
- object_not_found_exception(obj, nil)
59
- if item.is_a?(Integer)
60
- obj.find(:css, "#{@list_item}:nth-of-type(#{item})", visible: true, minimum: 0, wait: 2).hover
61
- elsif item.is_a?(String)
62
- items = obj.all(@list_item).collect(&:text)
63
- sleep(2) unless items.include?(item)
64
- obj.first(:css, @list_item, text: item, wait: 2).hover
50
+ # Hover over the specified item in a list object. Accepts a String or Integer.
51
+ #
52
+ # @param item [String, Integer] text or index of item to hover over
53
+ # @example
54
+ # province_list.hover_item(2)
55
+ # province_list.hover_item('Manitoba')
56
+ #
57
+ def hover_item(item)
58
+ obj, = find_element
59
+ object_not_found_exception(obj, nil)
60
+ if item.is_a?(Integer)
61
+ obj.find(:css, "#{@list_item}:nth-of-type(#{item})", visible: true, wait: 2).hover
62
+ elsif item.is_a?(String)
63
+ items = obj.all(@list_item).collect(&:text)
64
+ sleep(2) unless items.include?(item)
65
+ obj.first(:css, @list_item, text: item, wait: 2).hover
66
+ end
65
67
  end
66
- end
67
68
 
68
- # Return array of strings of all items in a list object.
69
- #
70
- # @return [Array]
71
- # @example
72
- # nav_items = nav_list.get_options
73
- #
74
- def get_list_items(element_spec = nil)
75
- define_list_elements(element_spec) unless element_spec.nil?
76
- obj, = find_element
77
- object_not_found_exception(obj, nil)
78
- items = obj.all(@list_item, visible: true, minimum: 0, wait: 2).collect(&:text)
79
-
80
- items.map!{ |item| item.delete("\n") }
81
- items.map!{ |item| item.delete("\r") }
82
- items.map!{ |item| item.delete("\t") }
83
- items.map!{ |item| item.strip }
84
- end
69
+ # Return array of strings of all items in a list object.
70
+ #
71
+ # @return [Array]
72
+ # @example
73
+ # nav_items = nav_list.get_options
74
+ #
75
+ def get_list_items(element_spec = nil)
76
+ define_list_elements(element_spec) unless element_spec.nil?
77
+ obj, = find_element
78
+ object_not_found_exception(obj, nil)
79
+ items = obj.all(@list_item, visible: true, minimum: 0, wait: 2).collect(&:text)
80
+
81
+ items.map!{ |item| item.delete("\n") }
82
+ items.map!{ |item| item.delete("\r") }
83
+ items.map!{ |item| item.delete("\t") }
84
+ items.map!{ |item| item.strip }
85
+ end
85
86
 
86
- def get_list_item(index, visible = true)
87
- items = visible ? get_list_items : get_all_list_items
88
- item = items[index - 1]
89
- item.delete!("\n")
90
- item.delete!("\r")
91
- item.delete!("\t")
92
- item.strip!
93
- end
87
+ def get_list_item(index, visible = true)
88
+ items = visible ? get_list_items : get_all_list_items
89
+ item = items[index - 1]
90
+ item.delete!("\n")
91
+ item.delete!("\r")
92
+ item.delete!("\t")
93
+ item.strip!
94
+ end
94
95
 
95
- # Return the number of items in a list object.
96
- #
97
- # @return [Integer]
98
- # @example
99
- # num_nav_items = nav_list.get_item_count
100
- #
101
- def get_item_count
102
- obj, = find_element
103
- object_not_found_exception(obj, nil)
104
- obj.all(@list_item, visible: true, minimum: 0, wait: 2).count
105
- end
96
+ # Return the number of items in a list object.
97
+ #
98
+ # @return [Integer]
99
+ # @example
100
+ # num_nav_items = nav_list.get_item_count
101
+ #
102
+ def get_item_count
103
+ obj, = find_element
104
+ object_not_found_exception(obj, nil)
105
+ obj.all(@list_item, visible: true, minimum: 0, wait: 2).count
106
+ end
106
107
 
107
- alias item_count get_item_count
108
+ alias item_count get_item_count
108
109
 
109
- def get_all_list_items(element_spec = nil)
110
- define_list_elements(element_spec) unless element_spec.nil?
111
- obj, = find_element
112
- object_not_found_exception(obj, nil)
113
- obj.all(@list_item, visible: :all).collect(&:text)
114
- end
110
+ def get_all_list_items(element_spec = nil)
111
+ define_list_elements(element_spec) unless element_spec.nil?
112
+ obj, = find_element
113
+ object_not_found_exception(obj, nil)
114
+ obj.all(@list_item, visible: :all).collect(&:text)
115
+ end
115
116
 
116
- def get_all_items_count
117
- obj, = find_element
118
- object_not_found_exception(obj, nil)
119
- obj.all(@list_item, visible: :all).count
120
- end
117
+ def get_all_items_count
118
+ obj, = find_element
119
+ object_not_found_exception(obj, nil)
120
+ obj.all(@list_item, visible: :all).count
121
+ end
121
122
 
122
- # Return text of first selected item in a list object.
123
- #
124
- # @return [String]
125
- # @example
126
- # current_selection = nav_list.get_selected_item
127
- #
128
- def get_selected_item
129
- obj, = find_element
130
- object_not_found_exception(obj, nil)
131
- obj.first(:css, @list_item, minimum: 0) ? obj.first(:css, @selected_item).text : nil
132
- end
123
+ # Return text of first selected item in a list object.
124
+ #
125
+ # @return [String]
126
+ # @example
127
+ # current_selection = nav_list.get_selected_item
128
+ #
129
+ def get_selected_item
130
+ obj, = find_element
131
+ object_not_found_exception(obj, nil)
132
+ obj.first(:css, @list_item, minimum: 0) ? obj.first(:css, @selected_item).text : nil
133
+ end
133
134
 
134
- alias selected? get_selected_item
135
+ alias selected? get_selected_item
135
136
 
136
- def verify_list_items(expected, enqueue = false)
137
- actual = get_list_items
138
- if enqueue
139
- ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{object_ref_message}")
140
- else
141
- assert_equal(expected, actual, "Expected list #{object_ref_message} to be #{expected} but found #{actual}")
137
+ def verify_list_items(expected, enqueue = false)
138
+ actual = get_list_items
139
+ if enqueue
140
+ ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{object_ref_message}")
141
+ else
142
+ assert_equal(expected, actual, "Expected list #{object_ref_message} to be #{expected} but found #{actual}")
143
+ end
142
144
  end
143
- end
144
145
 
145
- def get_list_row_locator(row)
146
- case @locator_type
147
- when :xpath
148
- "#{@locator}/#{@list_item}[#{row}]"
149
- when :css
150
- "#{@locator} > #{@list_item}:nth-of-type(#{row})"
146
+ def get_list_row_locator(row)
147
+ case @locator_type
148
+ when :xpath
149
+ "#{@locator}/#{@list_item}[#{row}]"
150
+ when :css
151
+ "#{@locator} > #{@list_item}:nth-of-type(#{row})"
152
+ end
151
153
  end
152
- end
153
154
 
154
- # Wait until the list's item count equals the specified value, or until the specified wait time has expired. If the wait
155
- # time is nil, then the wait time will be Capybara.default_max_wait_time.
156
- #
157
- # @param value [Integer or Hash] value expected or comparison hash
158
- # @param seconds [Integer or Float] wait time in seconds
159
- # @example
160
- # search_results_list.wait_until_item_count_is(10, 15)
161
- # or
162
- # search_results_list.wait_until_item_count_is({ greater_than_or_equal: 1 }, 5)
163
- #
164
- def wait_until_item_count_is(value, seconds = nil, post_exception = true)
165
- timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
166
- wait = Selenium::WebDriver::Wait.new(timeout: timeout)
167
- wait.until { compare(value, get_item_count) }
168
- rescue
169
- if post_exception
170
- raise "Value of List #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_item_count == value
171
- else
172
- get_item_count == value
155
+ # Wait until the list's item count equals the specified value, or until the specified wait time has expired. If the wait
156
+ # time is nil, then the wait time will be Capybara.default_max_wait_time.
157
+ #
158
+ # @param value [Integer or Hash] value expected or comparison hash
159
+ # @param seconds [Integer or Float] wait time in seconds
160
+ # @example
161
+ # search_results_list.wait_until_item_count_is(10, 15)
162
+ # or
163
+ # search_results_list.wait_until_item_count_is({ greater_than_or_equal: 1 }, 5)
164
+ #
165
+ def wait_until_item_count_is(value, seconds = nil, post_exception = true)
166
+ timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
167
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout)
168
+ wait.until { compare(value, get_item_count) }
169
+ rescue
170
+ if post_exception
171
+ raise "Value of List #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_item_count == value
172
+ else
173
+ get_item_count == value
174
+ end
173
175
  end
174
- end
175
176
 
176
- # Wait until the list's item count changes to a different value, or until the specified wait time has expired. If the
177
- # wait time is nil, then the wait time will be Capybara.default_max_wait_time.
178
- #
179
- # @param seconds [Integer or Float] wait time in seconds
180
- # @example
181
- # search_results_list.wait_until_value_changes(5)
182
- #
183
- def wait_until_item_count_changes(seconds = nil, post_exception = true)
184
- value = get_item_count
185
- timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
186
- wait = Selenium::WebDriver::Wait.new(timeout: timeout)
187
- wait.until { get_item_count != value }
188
- rescue
189
- if post_exception
190
- raise "Value of List #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_item_count == value
191
- else
192
- get_item_count == value
177
+ # Wait until the list's item count changes to a different value, or until the specified wait time has expired. If the
178
+ # wait time is nil, then the wait time will be Capybara.default_max_wait_time.
179
+ #
180
+ # @param seconds [Integer or Float] wait time in seconds
181
+ # @example
182
+ # search_results_list.wait_until_value_changes(5)
183
+ #
184
+ def wait_until_item_count_changes(seconds = nil, post_exception = true)
185
+ value = get_item_count
186
+ timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
187
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout)
188
+ wait.until { get_item_count != value }
189
+ rescue
190
+ if post_exception
191
+ raise "Value of List #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_item_count == value
192
+ else
193
+ get_item_count == value
194
+ end
193
195
  end
194
196
  end
195
197
  end