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,299 +1,301 @@
1
1
  module TestCentricity
2
- class SelectList < UIElement
3
- attr_accessor :list_item
4
- attr_accessor :selected_item
5
- attr_accessor :list_trigger
6
- attr_accessor :text_field
7
- attr_accessor :options_list
8
- attr_accessor :group_item
9
- attr_accessor :group_heading
2
+ module Elements
3
+ class SelectList < UIElement
4
+ attr_accessor :list_item
5
+ attr_accessor :selected_item
6
+ attr_accessor :list_trigger
7
+ attr_accessor :text_field
8
+ attr_accessor :options_list
9
+ attr_accessor :group_item
10
+ attr_accessor :group_heading
10
11
 
11
- def initialize(name, parent, locator, context)
12
- super
13
- @type = :selectlist
14
- list_spec = {
15
- selected_item: "li[class*='result-selected']",
16
- list_item: "li[class*='active-result']",
17
- list_trigger: nil,
18
- text_field: nil,
19
- options_list: nil,
20
- group_item: 'li.group-result',
21
- group_heading: 'li.group-result'
22
- }
23
- define_list_elements(list_spec)
24
- end
12
+ def initialize(name, parent, locator, context)
13
+ super
14
+ @type = :selectlist
15
+ list_spec = {
16
+ selected_item: "li[class*='result-selected']",
17
+ list_item: "li[class*='active-result']",
18
+ list_trigger: nil,
19
+ text_field: nil,
20
+ options_list: nil,
21
+ group_item: 'li.group-result',
22
+ group_heading: 'li.group-result'
23
+ }
24
+ define_list_elements(list_spec)
25
+ end
25
26
 
26
- def define_list_elements(element_spec)
27
- element_spec.each do |element, value|
28
- case element
29
- when :list_item
30
- @list_item = value
31
- when :selected_item
32
- @selected_item = value
33
- when :list_trigger
34
- @list_trigger = value
35
- when :text_field
36
- @text_field = value
37
- when :options_list
38
- @options_list = value
39
- when :group_item
40
- @group_item = value
41
- when :group_heading
42
- @group_heading = value
43
- else
44
- raise "#{element} is not a recognized selectlist element"
27
+ def define_list_elements(element_spec)
28
+ element_spec.each do |element, value|
29
+ case element
30
+ when :list_item
31
+ @list_item = value
32
+ when :selected_item
33
+ @selected_item = value
34
+ when :list_trigger
35
+ @list_trigger = value
36
+ when :text_field
37
+ @text_field = value
38
+ when :options_list
39
+ @options_list = value
40
+ when :group_item
41
+ @group_item = value
42
+ when :group_heading
43
+ @group_heading = value
44
+ else
45
+ raise "#{element} is not a recognized selectlist element"
46
+ end
45
47
  end
46
48
  end
47
- end
48
49
 
49
- # Select the specified option in a select box object. Accepts a String or Hash.
50
- # Supports standard HTML select objects and Chosen select objects.
51
- #
52
- # @param option [String] text of option to select
53
- # OR
54
- # @param option [Hash] :value, :index, or :text of option to select
55
- #
56
- # @example
57
- # province_select.choose_option('Alberta')
58
- # province_select.choose_option(value: 'AB')
59
- # state_select.choose_option(index: 24)
60
- # state_select.choose_option(text: 'Maryland')
61
- #
62
- def choose_option(option)
63
- @base_object, = find_element
64
- object_not_found_exception(@base_object, 'SelectList')
50
+ # Select the specified option in a select box object. Accepts a String or Hash.
51
+ # Supports standard HTML select objects and Chosen select objects.
52
+ #
53
+ # @param option [String] text of option to select
54
+ # OR
55
+ # @param option [Hash] :value, :index, or :text of option to select
56
+ #
57
+ # @example
58
+ # province_select.choose_option('Alberta')
59
+ # province_select.choose_option(value: 'AB')
60
+ # state_select.choose_option(index: 24)
61
+ # state_select.choose_option(text: 'Maryland')
62
+ #
63
+ def choose_option(option)
64
+ @base_object, = find_element
65
+ object_not_found_exception(@base_object, 'SelectList')
65
66
 
66
- trigger_list
67
+ trigger_list
67
68
 
68
- unless @options_list.nil?
69
- find_component(@options_list, 'drop menu')
70
- raise "Could not find option #{option} to choose" unless first(:css, @list_item, minimum: 0, wait: 5)
69
+ unless @options_list.nil?
70
+ find_component(@options_list, 'drop menu')
71
+ raise "Could not find option #{option} to choose" unless first(:css, @list_item, minimum: 0, wait: 5)
71
72
 
72
- if option.is_a?(Array)
73
- option.each do |item|
74
- page.find(:css, @list_item, text: item.strip).click
75
- end
76
- else
77
- if option.is_a?(Hash)
78
- @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index)
79
- @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value)
80
- @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text)
73
+ if option.is_a?(Array)
74
+ option.each do |item|
75
+ page.find(:css, @list_item, text: item.strip).click
76
+ end
81
77
  else
82
- options = @base_object.all(@list_item).collect(&:text)
83
- sleep(2) unless options.include?(option)
84
- first(:css, @list_item, text: option).click
78
+ if option.is_a?(Hash)
79
+ @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index)
80
+ @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value)
81
+ @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text)
82
+ else
83
+ options = @base_object.all(@list_item).collect(&:text)
84
+ sleep(2) unless options.include?(option)
85
+ first(:css, @list_item, text: option).click
86
+ end
85
87
  end
88
+ return
86
89
  end
87
- return
88
- end
89
90
 
90
- if first(:css, @list_item, minimum: 0, wait: 2)
91
- if option.is_a?(Array)
92
- option.each do |item|
93
- page.find(:css, @list_item, text: item.strip).click
91
+ if first(:css, @list_item, minimum: 0, wait: 2)
92
+ if option.is_a?(Array)
93
+ option.each do |item|
94
+ page.find(:css, @list_item, text: item.strip).click
95
+ end
96
+ else
97
+ if option.is_a?(Hash)
98
+ page.find(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index)
99
+ page.find(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value)
100
+ page.find(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text)
101
+ else
102
+ options = @base_object.all(@list_item).collect(&:text)
103
+ sleep(2) unless options.include?(option)
104
+ first(:css, @list_item, text: option).click
105
+ end
94
106
  end
95
107
  else
96
- if option.is_a?(Hash)
97
- page.find(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index)
98
- page.find(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value)
99
- page.find(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text)
108
+ if option.is_a?(Array)
109
+ option.each do |item|
110
+ select_item(@base_object, item)
111
+ end
100
112
  else
101
- options = @base_object.all(@list_item).collect(&:text)
102
- sleep(2) unless options.include?(option)
103
- first(:css, @list_item, text: option).click
113
+ select_item(@base_object, option)
104
114
  end
105
115
  end
106
- else
107
- if option.is_a?(Array)
108
- option.each do |item|
109
- select_item(@base_object, item)
110
- end
111
- else
112
- select_item(@base_object, option)
113
- end
114
116
  end
115
- end
116
117
 
117
- def set(text)
118
- raise "A 'text_field' list element must be defined before calling the 'set' method on a selectlist object" if @text_field.nil?
119
- @base_object, = find_element
120
- object_not_found_exception(@base_object, 'SelectList')
121
- trigger_list
122
- input = find_component(@text_field, 'text field')
123
- input.set("#{text}\n")
124
- end
118
+ def set(text)
119
+ raise "A 'text_field' list element must be defined before calling the 'set' method on a selectlist object" if @text_field.nil?
120
+ @base_object, = find_element
121
+ object_not_found_exception(@base_object, 'SelectList')
122
+ trigger_list
123
+ input = find_component(@text_field, 'text field')
124
+ input.set("#{text}\n")
125
+ end
125
126
 
126
- # Return array of strings of all options in a select box object.
127
- # Supports standard HTML select objects and Chosen select objects.
128
- #
129
- # @return [Array]
130
- # @example
131
- # all_colors = color_select.get_options
132
- #
133
- def get_options
134
- @base_object, = find_element
135
- object_not_found_exception(@base_object, 'SelectList')
136
- if @options_list.nil?
137
- if @base_object.first(:css, @list_item, minimum: 0, wait: 2)
138
- @base_object.all(@list_item).collect(&:text)
127
+ # Return array of strings of all options in a select box object.
128
+ # Supports standard HTML select objects and Chosen select objects.
129
+ #
130
+ # @return [Array]
131
+ # @example
132
+ # all_colors = color_select.get_options
133
+ #
134
+ def get_options
135
+ @base_object, = find_element
136
+ object_not_found_exception(@base_object, 'SelectList')
137
+ if @options_list.nil?
138
+ if @base_object.first(:css, @list_item, minimum: 0, wait: 2)
139
+ @base_object.all(@list_item).collect(&:text)
140
+ else
141
+ @base_object.all('option', visible: :all).collect(&:text)
142
+ end
139
143
  else
140
- @base_object.all('option', visible: :all).collect(&:text)
144
+ trigger_list
145
+ menu = find_component(@options_list, 'drop menu')
146
+ options = menu.all(@list_item, visible: true, minimum: 0, wait: 2).collect(&:text)
147
+ trigger_list
148
+ options
141
149
  end
142
- else
143
- trigger_list
144
- menu = find_component(@options_list, 'drop menu')
145
- options = menu.all(@list_item, visible: true, minimum: 0, wait: 2).collect(&:text)
146
- trigger_list
147
- options
148
150
  end
149
- end
150
151
 
151
- alias get_list_items get_options
152
+ alias get_list_items get_options
152
153
 
153
- # Return the number of options in a select box object.
154
- # Supports standard HTML select objects and Chosen select objects.
155
- #
156
- # @return [Integer]
157
- # @example
158
- # num_colors = color_select.get_option_count
159
- #
160
- def get_option_count
161
- @base_object, = find_element
162
- object_not_found_exception(@base_object, 'SelectList')
163
- if @options_list.nil?
164
- if @base_object.first(:css, @list_item, minimum: 0, wait: 2)
165
- @base_object.all(@list_item).count
154
+ # Return the number of options in a select box object.
155
+ # Supports standard HTML select objects and Chosen select objects.
156
+ #
157
+ # @return [Integer]
158
+ # @example
159
+ # num_colors = color_select.get_option_count
160
+ #
161
+ def get_option_count
162
+ @base_object, = find_element
163
+ object_not_found_exception(@base_object, 'SelectList')
164
+ if @options_list.nil?
165
+ if @base_object.first(:css, @list_item, minimum: 0, wait: 2)
166
+ @base_object.all(@list_item).count
167
+ else
168
+ @base_object.all('option', visible: :all).count
169
+ end
166
170
  else
167
- @base_object.all('option', visible: :all).count
171
+ trigger_list
172
+ menu = find_component(@options_list, 'drop menu')
173
+ num_items = menu.all(@list_item, visible: true, minimum: 0, wait: 2).count
174
+ trigger_list
175
+ num_items
168
176
  end
169
- else
170
- trigger_list
171
- menu = find_component(@options_list, 'drop menu')
172
- num_items = menu.all(@list_item, visible: true, minimum: 0, wait: 2).count
173
- trigger_list
174
- num_items
175
177
  end
176
- end
177
178
 
178
- alias get_item_count get_option_count
179
+ alias get_item_count get_option_count
179
180
 
180
- # Return array of strings of all group headings in a select box object.
181
- # Supports React and Chosen select objects.
182
- #
183
- # @return [Array]
184
- # @example
185
- # regions = team_select.get_group_headings
186
- #
187
- def get_group_headings
188
- @base_object, = find_element
189
- object_not_found_exception(@base_object, 'SelectList')
190
- if @options_list.nil?
191
- if @base_object.first(:css, @group_heading, minimum: 0, wait: 2)
192
- @base_object.all(@group_heading).collect(&:text)
181
+ # Return array of strings of all group headings in a select box object.
182
+ # Supports React and Chosen select objects.
183
+ #
184
+ # @return [Array]
185
+ # @example
186
+ # regions = team_select.get_group_headings
187
+ #
188
+ def get_group_headings
189
+ @base_object, = find_element
190
+ object_not_found_exception(@base_object, 'SelectList')
191
+ if @options_list.nil?
192
+ if @base_object.first(:css, @group_heading, minimum: 0, wait: 2)
193
+ @base_object.all(@group_heading).collect(&:text)
194
+ else
195
+ nil
196
+ end
193
197
  else
194
- nil
198
+ trigger_list
199
+ menu = find_component(@options_list, 'drop menu')
200
+ groups = menu.all(@group_heading, visible: true, minimum: 0, wait: 2).collect(&:text)
201
+ trigger_list
202
+ groups
195
203
  end
196
- else
197
- trigger_list
198
- menu = find_component(@options_list, 'drop menu')
199
- groups = menu.all(@group_heading, visible: true, minimum: 0, wait: 2).collect(&:text)
200
- trigger_list
201
- groups
202
204
  end
203
- end
204
205
 
205
- # Return the number of groups in a select box object.
206
- # Supports React and Chosen select objects.
207
- #
208
- # @return [Integer]
209
- # @example
210
- # num_regions = team_select.get_group_count
211
- #
212
- def get_group_count
213
- @base_object, = find_element
214
- object_not_found_exception(@base_object, 'SelectList')
215
- if @options_list.nil?
216
- if @base_object.first(:css, @group_item, minimum: 0, wait: 2)
217
- @base_object.all(@group_item).count
206
+ # Return the number of groups in a select box object.
207
+ # Supports React and Chosen select objects.
208
+ #
209
+ # @return [Integer]
210
+ # @example
211
+ # num_regions = team_select.get_group_count
212
+ #
213
+ def get_group_count
214
+ @base_object, = find_element
215
+ object_not_found_exception(@base_object, 'SelectList')
216
+ if @options_list.nil?
217
+ if @base_object.first(:css, @group_item, minimum: 0, wait: 2)
218
+ @base_object.all(@group_item).count
219
+ else
220
+ 0
221
+ end
218
222
  else
219
- 0
223
+ trigger_list
224
+ menu = find_component(@options_list, 'drop menu')
225
+ num_items = menu.all(@group_item, visible: true, minimum: 0, wait: 2).count
226
+ trigger_list
227
+ num_items
220
228
  end
221
- else
222
- trigger_list
223
- menu = find_component(@options_list, 'drop menu')
224
- num_items = menu.all(@group_item, visible: true, minimum: 0, wait: 2).count
225
- trigger_list
226
- num_items
227
229
  end
228
- end
229
230
 
230
- def verify_options(expected, enqueue = false)
231
- actual = get_options
232
- if enqueue
233
- ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{object_ref_message}")
234
- else
235
- assert_equal(expected, actual, "Expected list of options in list #{object_ref_message} to be #{expected} but found #{actual}")
231
+ def verify_options(expected, enqueue = false)
232
+ actual = get_options
233
+ if enqueue
234
+ ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{object_ref_message}")
235
+ else
236
+ assert_equal(expected, actual, "Expected list of options in list #{object_ref_message} to be #{expected} but found #{actual}")
237
+ end
236
238
  end
237
- end
238
239
 
239
- # Return text of first selected option in a select box object.
240
- # Supports standard HTML select objects and Chosen select objects.
241
- #
242
- # @return [String]
243
- # @example
244
- # current_color = color_select.get_selected_option
245
- #
246
- def get_selected_option
247
- @base_object, = find_element
248
- object_not_found_exception(@base_object, 'SelectList')
249
- trigger_list unless @options_list.nil?
250
- selection = if @base_object.first(:css, @list_item, minimum: 0, wait: 1, visible: :all)
251
- @base_object.first(:css, @selected_item, wait: 1, visible: :all).text
252
- elsif @base_object.first(:css, @selected_item, minimum: 0, wait: 1, visible: :all)
253
- @base_object.first(:css, @selected_item, visible: :all).text
254
- elsif @base_object.first('option[selected]', minimum: 0, wait: 1, visible: :all)
255
- @base_object.first('option[selected]', wait: 1, visible: :all).text
256
- else
257
- index = get_attribute(:selectedIndex).to_i
258
- if index >= 0
259
- options = get_options
260
- options[index]
240
+ # Return text of first selected option in a select box object.
241
+ # Supports standard HTML select objects and Chosen select objects.
242
+ #
243
+ # @return [String]
244
+ # @example
245
+ # current_color = color_select.get_selected_option
246
+ #
247
+ def get_selected_option
248
+ @base_object, = find_element
249
+ object_not_found_exception(@base_object, 'SelectList')
250
+ trigger_list unless @options_list.nil?
251
+ selection = if @base_object.first(:css, @list_item, minimum: 0, wait: 1, visible: :all)
252
+ @base_object.first(:css, @selected_item, wait: 1, visible: :all).text
253
+ elsif @base_object.first(:css, @selected_item, minimum: 0, wait: 1, visible: :all)
254
+ @base_object.first(:css, @selected_item, visible: :all).text
255
+ elsif @base_object.first('option[selected]', minimum: 0, wait: 1, visible: :all)
256
+ @base_object.first('option[selected]', wait: 1, visible: :all).text
261
257
  else
262
- ''
258
+ index = get_attribute(:selectedIndex).to_i
259
+ if index >= 0
260
+ options = get_options
261
+ options[index]
262
+ else
263
+ ''
264
+ end
263
265
  end
264
- end
265
- trigger_list unless @options_list.nil?
266
- selection
267
- end
266
+ trigger_list unless @options_list.nil?
267
+ selection
268
+ end
268
269
 
269
- alias selected? get_selected_option
270
+ alias selected? get_selected_option
270
271
 
271
- private
272
+ private
272
273
 
273
- def select_item(obj, option)
274
- if option.is_a?(Hash)
275
- obj.find("option[value='#{option[:value]}']").click if option.key?(:value)
274
+ def select_item(obj, option)
275
+ if option.is_a?(Hash)
276
+ obj.find("option[value='#{option[:value]}']").click if option.key?(:value)
276
277
 
277
- if option.key?(:index)
278
- if @locator_type == :xpath
279
- obj.find(:xpath, "option[#{option[:index]}]").select_option
280
- else
281
- obj.find(:css, "option:nth-child(#{option[:index]})").select_option
278
+ if option.key?(:index)
279
+ if @locator_type == :xpath
280
+ obj.find(:xpath, "option[#{option[:index]}]").select_option
281
+ else
282
+ obj.find(:css, "option:nth-child(#{option[:index]})").select_option
283
+ end
282
284
  end
283
- end
284
285
 
285
- obj.select option[:text] if option.key?(:text)
286
- else
287
- obj.select(option, visible: :all)
286
+ obj.select option[:text] if option.key?(:text)
287
+ else
288
+ obj.select(option, visible: :all)
289
+ end
288
290
  end
289
- end
290
291
 
291
- def trigger_list
292
- if @list_trigger.nil?
293
- @base_object.click
294
- else
295
- trigger = find_component(@list_trigger, 'trigger')
296
- trigger.click
292
+ def trigger_list
293
+ if @list_trigger.nil?
294
+ @base_object.click
295
+ else
296
+ trigger = find_component(@list_trigger, 'trigger')
297
+ trigger.click
298
+ end
297
299
  end
298
300
  end
299
301
  end