testcentricity_web 2.1.8.2 → 2.1.8.3

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +27 -0
  3. data/.rubocop.yml +41 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +28 -0
  7. data/README.md +1438 -0
  8. data/Rakefile +1 -0
  9. data/lib/devices/devices.yml +280 -0
  10. data/lib/testcentricity_web.rb +140 -0
  11. data/lib/testcentricity_web/browser_helper.rb +173 -0
  12. data/lib/testcentricity_web/data_objects_helper.rb +78 -0
  13. data/lib/testcentricity_web/drag_drop_helper.rb +15 -0
  14. data/lib/testcentricity_web/elements/button.rb +8 -0
  15. data/lib/testcentricity_web/elements/cell_button.rb +8 -0
  16. data/lib/testcentricity_web/elements/cell_checkbox.rb +38 -0
  17. data/lib/testcentricity_web/elements/cell_element.rb +62 -0
  18. data/lib/testcentricity_web/elements/cell_image.rb +8 -0
  19. data/lib/testcentricity_web/elements/cell_radio.rb +31 -0
  20. data/lib/testcentricity_web/elements/checkbox.rb +99 -0
  21. data/lib/testcentricity_web/elements/file_field.rb +45 -0
  22. data/lib/testcentricity_web/elements/image.rb +34 -0
  23. data/lib/testcentricity_web/elements/label.rb +8 -0
  24. data/lib/testcentricity_web/elements/link.rb +8 -0
  25. data/lib/testcentricity_web/elements/list.rb +54 -0
  26. data/lib/testcentricity_web/elements/list_button.rb +8 -0
  27. data/lib/testcentricity_web/elements/list_checkbox.rb +38 -0
  28. data/lib/testcentricity_web/elements/list_element.rb +51 -0
  29. data/lib/testcentricity_web/elements/list_radio.rb +31 -0
  30. data/lib/testcentricity_web/elements/radio.rb +73 -0
  31. data/lib/testcentricity_web/elements/select_list.rb +189 -0
  32. data/lib/testcentricity_web/elements/table.rb +473 -0
  33. data/lib/testcentricity_web/elements/textfield.rb +84 -0
  34. data/lib/testcentricity_web/environment.rb +249 -0
  35. data/lib/testcentricity_web/excel_helper.rb +242 -0
  36. data/lib/testcentricity_web/exception_queue_helper.rb +47 -0
  37. data/lib/testcentricity_web/page_objects_helper.rb +656 -0
  38. data/lib/testcentricity_web/page_sections_helper.rb +811 -0
  39. data/lib/testcentricity_web/siebel_open_ui_helper.rb +15 -0
  40. data/lib/testcentricity_web/ui_elements_helper.rb +425 -0
  41. data/lib/testcentricity_web/utility_helpers.rb +28 -0
  42. data/lib/testcentricity_web/version.rb +3 -0
  43. data/lib/testcentricity_web/webdriver_helper.rb +451 -0
  44. data/lib/testcentricity_web/world_extensions.rb +26 -0
  45. data/testcentricity_web.gemspec +42 -0
  46. metadata +52 -4
@@ -0,0 +1,811 @@
1
+ require 'test/unit'
2
+
3
+ module TestCentricity
4
+ class PageSection
5
+ include Capybara::DSL
6
+ include Capybara::Node::Matchers
7
+ include Test::Unit::Assertions
8
+
9
+ attr_reader :context, :name
10
+ attr_accessor :locator
11
+ attr_accessor :parent
12
+ attr_accessor :parent_list
13
+ attr_accessor :list_index
14
+
15
+ def initialize(name, parent, locator, context)
16
+ @name = name
17
+ @parent = parent
18
+ @locator = locator
19
+ @context = context
20
+ @parent_list = nil
21
+ @list_index = nil
22
+ end
23
+
24
+ def get_locator
25
+ if @locator.empty? && defined?(section_locator)
26
+ locator = section_locator
27
+ else
28
+ locator = @locator
29
+ end
30
+
31
+ unless @parent_list.nil?
32
+ locator = "#{@parent_list.get_locator}|#{locator}"
33
+ unless @list_index.nil?
34
+ if locator.include?('/')
35
+ locator = "(#{locator})[#{@list_index}]"
36
+ else
37
+ locator = "#{locator}:nth-of-type(#{@list_index})"
38
+ end
39
+ end
40
+ end
41
+
42
+ if @context == :section && !@parent.nil? && !@parent.get_locator.nil?
43
+ "#{@parent.get_locator}|#{locator}"
44
+ else
45
+ locator
46
+ end
47
+ end
48
+
49
+ def set_list_index(list, index = 1)
50
+ @parent_list = list unless list.nil?
51
+ @list_index = index
52
+ end
53
+
54
+ def get_item_count
55
+ raise 'No parent list defined' if @parent_list.nil?
56
+ @parent_list.get_item_count
57
+ end
58
+
59
+ def get_list_items
60
+ items = []
61
+ (1..get_item_count).each do |item|
62
+ set_list_index(nil, item)
63
+ items.push(get_value)
64
+ end
65
+ items
66
+ end
67
+
68
+ def verify_list_items(expected, enqueue = false)
69
+ actual = get_list_items
70
+ enqueue ?
71
+ ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{object_ref_message}") :
72
+ assert_equal(expected, actual, "Expected list object '#{get_name}' (#{get_locator}) to be #{expected} but found #{actual}")
73
+ end
74
+
75
+ def get_object_type
76
+ :section
77
+ end
78
+
79
+ def get_name
80
+ @name
81
+ end
82
+
83
+ def set_parent(parent)
84
+ @parent = parent
85
+ end
86
+
87
+ # Define a trait for this page section.
88
+ #
89
+ # @param trait_name [Symbol] name of trait (as a symbol)
90
+ # @param block [&block] trait value
91
+ # @example
92
+ # trait(:section_locator) { "//div[@class='Messaging_Applet']" }
93
+ # trait(:list_table_name) { '#Messages' }
94
+ #
95
+ def self.trait(trait_name, &block)
96
+ define_method(trait_name.to_s, &block)
97
+ end
98
+
99
+ # Declare and instantiate a single generic UI Element for this page section.
100
+ #
101
+ # @param element_name [Symbol] name of UI object (as a symbol)
102
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
103
+ # @example
104
+ # element :undo_record_item, "//li[@rn='Undo Record']/a"
105
+ # element :basket_header, 'div.basket_header'
106
+ #
107
+ def self.element(element_name, locator)
108
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::UIElement.new("#{element_name}", self, "#{locator}", :section);end))
109
+ end
110
+
111
+ # Declare and instantiate a collection of generic UI Elements for this page section.
112
+ #
113
+ # @param element_hash [Hash] names of UI objects (as a symbol) and CSS selectors or XPath expressions that uniquely identifies objects
114
+ # @example
115
+ # elements profile_item: 'a#profile',
116
+ # settings_item: 'a#userPreferencesTrigger',
117
+ # log_out_item: 'a#logout'
118
+ #
119
+ def self.elements(element_hash)
120
+ element_hash.each do |element_name, locator|
121
+ element(element_name, locator)
122
+ end
123
+ end
124
+
125
+ # Declare and instantiate a single button UI Element for this page section.
126
+ #
127
+ # @param element_name [Symbol] name of button object (as a symbol)
128
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
129
+ # @example
130
+ # button :checkout_button, 'button.checkout_button'
131
+ # button :login_button, "//input[@id='submit_button']"
132
+ #
133
+ def self.button(element_name, locator)
134
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Button.new("#{element_name}", self, "#{locator}", :section);end))
135
+ end
136
+
137
+ # Declare and instantiate a collection of buttons for this page section.
138
+ #
139
+ # @param element_hash [Hash] names of buttons (as a symbol) and CSS selectors or XPath expressions that uniquely identifies buttons
140
+ # @example
141
+ # buttons new_account_button: 'button#new-account',
142
+ # save_button: 'button#save',
143
+ # cancel_button: 'button#cancel'
144
+ #
145
+ def self.buttons(element_hash)
146
+ element_hash.each do |element_name, locator|
147
+ button(element_name, locator)
148
+ end
149
+ end
150
+
151
+ # Declare and instantiate a single text field UI Element for this page section.
152
+ #
153
+ # @param element_name [Symbol] name of text field object (as a symbol)
154
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
155
+ # @example
156
+ # textfield :user_id_field, "//input[@id='UserName']"
157
+ # textfield :password_field, 'input#consumer_password'
158
+ #
159
+ def self.textfield(element_name, locator)
160
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::TextField.new("#{element_name}", self, "#{locator}", :section);end))
161
+ end
162
+
163
+ # Declare and instantiate a collection of text fields for this page section.
164
+ #
165
+ # @param element_hash [Hash] names of text fields (as a symbol) and CSS selectors or XPath expressions that uniquely identifies text fields
166
+ # @example
167
+ # textfields name_field: 'input#Name',
168
+ # title_field: 'input#Title',
169
+ # phone_field: 'input#PhoneNumber',
170
+ # fax_field: 'input#FaxNumber',
171
+ # email_field: 'input#Email'
172
+ #
173
+ def self.textfields(element_hash)
174
+ element_hash.each do |element_name, locator|
175
+ textfield(element_name, locator)
176
+ end
177
+ end
178
+
179
+ # Declare and instantiate a single checkbox UI Element for this page section.
180
+ #
181
+ # @param element_name [Symbol] name of checkbox object (as a symbol)
182
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
183
+ # @param proxy [Symbol] Optional name (as a symbol) of proxy object to receive click actions
184
+ # @example
185
+ # checkbox :remember_checkbox, "//input[@id='RememberUser']"
186
+ # checkbox :accept_terms_checkbox, 'input#accept_terms_conditions', :accept_terms_label
187
+ #
188
+ def self.checkbox(element_name, locator, proxy = nil)
189
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CheckBox.new("#{element_name}", self, "#{locator}", :section, #{proxy});end))
190
+ end
191
+
192
+ # Declare and instantiate a collection of checkboxes for this page section.
193
+ #
194
+ # @param element_hash [Hash] names of checkboxes (as a symbol) and CSS selectors or XPath expressions that uniquely identifies checkboxes
195
+ # @example
196
+ # checkboxes hazmat_certified_check: 'input#hazmatCertified',
197
+ # epa_certified_check: 'input#epaCertified',
198
+ # dhs_certified_check: 'input#homelandSecurityCertified',
199
+ # carb_compliant_check: 'input#carbCompliant'
200
+ #
201
+ def self.checkboxes(element_hash)
202
+ element_hash.each do |element_name, locator|
203
+ checkbox(element_name, locator)
204
+ end
205
+ end
206
+
207
+ # Declare and instantiate a single radio button UI Element for this page section.
208
+ #
209
+ # @param element_name [Symbol] name of radio object (as a symbol)
210
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
211
+ # @param proxy [Symbol] Optional name (as a symbol) of proxy object to receive click actions
212
+ # @example
213
+ # radio :accept_terms_radio, "//input[@id='Accept_Terms']"
214
+ # radio :decline_terms_radio, 'input#decline_terms_conditions', :decline_terms_label
215
+ #
216
+ def self.radio(element_name, locator, proxy = nil)
217
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Radio.new("#{element_name}", self, "#{locator}", :section, #{proxy});end))
218
+ end
219
+
220
+ # Declare and instantiate a collection of radio buttons for this page section.
221
+ #
222
+ # @param element_hash [Hash] names of radio buttons (as a symbol) and CSS selectors or XPath expressions that uniquely identifies radio buttons
223
+ # @example
224
+ # radios visa_radio: 'input#payWithVisa',
225
+ # mastercard_radio: 'input#payWithMastercard',
226
+ # discover_radio: 'input#payWithDiscover',
227
+ # amex_radio: 'input#payWithAmEx'
228
+ #
229
+ def self.radios(element_hash)
230
+ element_hash.each do |element_name, locator|
231
+ radio(element_name, locator)
232
+ end
233
+ end
234
+
235
+ # Declare and instantiate a single label UI Element for this page section.
236
+ #
237
+ # @param element_name [Symbol] name of label object (as a symbol)
238
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
239
+ # @example
240
+ # label :welcome_label, 'div.Welcome'
241
+ # label :rollup_price_label, "//div[contains(@id, 'Rollup Item Price')]"
242
+ #
243
+ def self.label(element_name, locator)
244
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Label.new("#{element_name}", self, "#{locator}", :section);end))
245
+ end
246
+
247
+ def self.labels(element_hash)
248
+ element_hash.each do |element_name, locator|
249
+ label(element_name, locator)
250
+ end
251
+ end
252
+
253
+ # Declare and instantiate a single link UI Element for this page section.
254
+ #
255
+ # @param element_name [Symbol] name of link object (as a symbol)
256
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
257
+ # @example
258
+ # link :registration_link, 'a.account-nav__link.register'
259
+ # link :shopping_basket_link, "//a[@href='shopping_basket']"
260
+ #
261
+ def self.link(element_name, locator)
262
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Link.new("#{element_name}", self, "#{locator}", :section);end))
263
+ end
264
+
265
+ def self.links(element_hash)
266
+ element_hash.each do |element_name, locator|
267
+ link(element_name, locator)
268
+ end
269
+ end
270
+
271
+ # Declare and instantiate a single table UI Element for this page section.
272
+ #
273
+ # @param element_name [Symbol] name of table object (as a symbol)
274
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
275
+ # @example
276
+ # table :payments_table, "//table[@class='payments_table']"
277
+ #
278
+ def self.table(element_name, locator)
279
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Table.new("#{element_name}", self, "#{locator}", :section);end))
280
+ end
281
+
282
+ def self.tables(element_hash)
283
+ element_hash.each do |element_name, locator|
284
+ table(element_name, locator)
285
+ end
286
+ end
287
+
288
+ # Declare and instantiate a single select list UI Element for this page section.
289
+ #
290
+ # @param element_name [Symbol] name of select list object (as a symbol)
291
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
292
+ # @example
293
+ # selectlist :category_selector, 'select#search_form_category_chosen'
294
+ # selectlist :gender_select, "//select[@id='customer_gender']"
295
+ #
296
+ def self.selectlist(element_name, locator)
297
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::SelectList.new("#{element_name}", self, "#{locator}", :section);end))
298
+ end
299
+
300
+ def self.selectlists(element_hash)
301
+ element_hash.each do |element_name, locator|
302
+ selectlist(element_name, locator)
303
+ end
304
+ end
305
+
306
+ # Declare and instantiate a single list UI Element for this page section.
307
+ #
308
+ # @param element_name [Symbol] name of list object (as a symbol)
309
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
310
+ # @example
311
+ # list :y_axis_list, 'g.y_axis'
312
+ #
313
+ def self.list(element_name, locator)
314
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::List.new("#{element_name}", self, "#{locator}", :section);end))
315
+ end
316
+
317
+ def self.lists(element_hash)
318
+ element_hash.each do |element_name, locator|
319
+ list(element_name, locator)
320
+ end
321
+ end
322
+
323
+ # Declare and instantiate an single image UI Element for this page section.
324
+ #
325
+ # @param element_name [Symbol] name of image object (as a symbol)
326
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
327
+ # @example
328
+ # image :basket_item_image, 'div.product_image'
329
+ # image :corporate_logo_image, "//img[@alt='MyCompany_logo']"
330
+ #
331
+ def self.image(element_name, locator)
332
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Image.new("#{element_name}", self, "#{locator}", :section);end))
333
+ end
334
+
335
+ def self.images(element_hash)
336
+ element_hash.each do |element_name, locator|
337
+ image(element_name, locator)
338
+ end
339
+ end
340
+
341
+ # Declare and instantiate a single File Field UI Element for this page section.
342
+ #
343
+ # @param element_name [Symbol] name of file field object (as a symbol)
344
+ # @param locator [String] CSS selector or XPath expression that uniquely identifies object
345
+ # @example
346
+ # filefield :attach_file, 's_SweFileName'
347
+ #
348
+ def self.filefield(element_name, locator)
349
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::FileField.new("#{element_name}", self, "#{locator}", :section);end))
350
+ end
351
+
352
+ def self.filefields(element_hash)
353
+ element_hash.each do |element_name, locator|
354
+ filefield(element_name, locator)
355
+ end
356
+ end
357
+
358
+ # Declare and instantiate a cell button in a table column on this page section.
359
+ #
360
+ # @param element_name [Symbol] name of cell button object (as a symbol)
361
+ # @param locator [String] XPath expression that uniquely identifies cell button within row and column of parent table object
362
+ # @param table [Symbol] Name (as a symbol) of parent table object
363
+ # @param column [Integer] 1-based index of table column that contains the cell button object
364
+ # @example
365
+ # cell_button :show_button, "a[@class='show']", :data_table, 5
366
+ # cell_button :edit_button, "a[@class='edit']", :data_table, 5
367
+ #
368
+ def self.cell_button(element_name, locator, table, column)
369
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellButton.new("#{element_name}", self, "#{locator}", :section, #{table}, #{column});end))
370
+ end
371
+
372
+ # Declare and instantiate a cell checkbox in a table column on this page section.
373
+ #
374
+ # @param element_name [Symbol] name of cell checkbox object (as a symbol)
375
+ # @param locator [String] XPath expression that uniquely identifies cell checkbox within row and column of parent table object
376
+ # @param table [Symbol] Name (as a symbol) of parent table object
377
+ # @param column [Integer] 1-based index of table column that contains the cell checkbox object
378
+ # @example
379
+ # cell_checkbox :is_registered_check, "a[@class='registered']", :data_table, 4
380
+ #
381
+ def self.cell_checkbox(element_name, locator, table, column, proxy = nil)
382
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellCheckBox.new("#{element_name}", self, "#{locator}", :section, #{table}, #{column}, #{proxy});end))
383
+ end
384
+
385
+ # Declare and instantiate a cell radio in a table column on this page section.
386
+ #
387
+ # @param element_name [Symbol] name of cell radio object (as a symbol)
388
+ # @param locator [String] XPath expression that uniquely identifies cell radio within row and column of parent table object
389
+ # @param table [Symbol] Name (as a symbol) of parent table object
390
+ # @param column [Integer] 1-based index of table column that contains the cell radio object
391
+ # @example
392
+ # cell_radio :track_a_radio, "a[@class='track_a']", :data_table, 8
393
+ #
394
+ def self.cell_radio(element_name, locator, table, column, proxy = nil)
395
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellRadio.new("#{element_name}", self, "#{locator}", :section, #{table}, #{column}, #{proxy});end))
396
+ end
397
+
398
+ # Declare and instantiate a cell image in a table column on this page object.
399
+ #
400
+ # @param element_name [Symbol] name of cell image object (as a symbol)
401
+ # @param locator [String] XPath expression that uniquely identifies cell image within row and column of parent table object
402
+ # @param table [Symbol] Name (as a symbol) of parent table object
403
+ # @param column [Integer] 1-based index of table column that contains the cell image object
404
+ # @example
405
+ # cell_image :ready_icon, "img[@class='ready']", :data_table, 3
406
+ # cell_image :send_icon, "img[@class='send']", :data_table, 3
407
+ #
408
+ def self.cell_image(element_name, locator, table, column)
409
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellImage.new("#{element_name}", self, "#{locator}", :section, #{table}, #{column});end))
410
+ end
411
+
412
+ # Declare and instantiate a list button in a row of a list object on this section object.
413
+ #
414
+ # @param element_name [Symbol] name of list button object (as a symbol)
415
+ # @param locator [String] XPath expression that uniquely identifies list button within row of parent list object
416
+ # @param list [Symbol] Name (as a symbol) of parent list object
417
+ # @example
418
+ # list_button :delete_button, "a[@class='delete']", :icon_list
419
+ # list_button :edit_button, "a[@class='edit']", :icon_list
420
+ #
421
+ def self.list_button(element_name, locator, list)
422
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::ListButton.new("#{element_name}", self, "#{locator}", :section, #{list});end))
423
+ end
424
+
425
+ # Declare and instantiate a list checkbox in a row of a list object on this section object.
426
+ #
427
+ # @param element_name [Symbol] name of list checkbox object (as a symbol)
428
+ # @param locator [String] XPath expression that uniquely identifies list checkbox within row of parent list object
429
+ # @param list [Symbol] Name (as a symbol) of parent list object
430
+ # @example
431
+ # list_checkbox :is_registered_check, "a[@class='registered']", :data_list
432
+ #
433
+ def self.list_checkbox(element_name, locator, list, proxy = nil)
434
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::ListCheckBox.new("#{element_name}", self, "#{locator}", :section, #{list}, #{proxy});end))
435
+ end
436
+
437
+ # Declare and instantiate a list radio in a row of a list object on this section object.
438
+ #
439
+ # @param element_name [Symbol] name of list radio object (as a symbol)
440
+ # @param locator [String] XPath expression that uniquely identifies list radio within row of parent list object
441
+ # @param list [Symbol] Name (as a symbol) of parent list object
442
+ # @example
443
+ # list_radio :sharing_radio, "a[@class='sharing']", :data_list
444
+ #
445
+ def self.list_radio(element_name, locator, list, proxy = nil)
446
+ class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellRadio.new("#{element_name}", self, "#{locator}", :section, #{list}, #{proxy});end))
447
+ end
448
+
449
+ # Instantiate a single PageSection object within this PageSection object.
450
+ #
451
+ # @param section_name [Symbol] name of PageSection object (as a symbol)
452
+ # @param class_name [String] Class name of PageSection object
453
+ # @example
454
+ # section :search_form, SearchForm
455
+ #
456
+ def self.section(section_name, class_name, locator = nil)
457
+ class_eval(%(def #{section_name};@#{section_name} ||= #{class_name}.new("#{section_name}", self, "#{locator}", :section);end))
458
+ end
459
+
460
+ def self.sections(section_hash)
461
+ section_hash.each do |section_name, class_name|
462
+ section(section_name, class_name)
463
+ end
464
+ end
465
+
466
+ # Does Section object exists?
467
+ #
468
+ # @return [Boolean]
469
+ # @example
470
+ # navigation_toolbar.exists?
471
+ #
472
+ def exists?
473
+ section, = find_section
474
+ section != nil
475
+ end
476
+
477
+ # Is Section object enabled?
478
+ #
479
+ # @return [Boolean]
480
+ # @example
481
+ # bar_chart_section.enabled?
482
+ #
483
+ def enabled?
484
+ !disabled?
485
+ end
486
+
487
+ # Is Section object disabled (not enabled)?
488
+ #
489
+ # @return [Boolean]
490
+ # @example
491
+ # bar_chart_section.disabled?
492
+ #
493
+ def disabled?
494
+ obj, = find_element
495
+ object_not_found_exception(obj, nil)
496
+ obj.disabled?
497
+ end
498
+
499
+ # Is Section object visible?
500
+ #
501
+ # @return [Boolean]
502
+ # @example
503
+ # navigation_toolbar.visible?
504
+ #
505
+ def visible?
506
+ section, = find_section
507
+ exists = section
508
+ visible = false
509
+ visible = section.visible? if exists
510
+ # the section is visible if it exists and it is not invisible
511
+ exists && visible ? true : false
512
+ end
513
+
514
+ # Is Section object hidden (not visible)?
515
+ #
516
+ # @return [Boolean]
517
+ # @example
518
+ # navigation_toolbar.hidden?
519
+ #
520
+ def hidden?
521
+ !visible?
522
+ end
523
+
524
+ # Wait until the Section object exists, or until the specified wait time has expired.
525
+ #
526
+ # @param seconds [Integer or Float] wait time in seconds
527
+ # @example
528
+ # navigation_toolbar.wait_until_exists(0.5)
529
+ #
530
+ def wait_until_exists(seconds = nil)
531
+ timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
532
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout)
533
+ wait.until { exists? }
534
+ rescue
535
+ raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless exists?
536
+ end
537
+
538
+ # Wait until the Section object no longer exists, or until the specified wait time has expired.
539
+ #
540
+ # @param seconds [Integer or Float] wait time in seconds
541
+ # @example
542
+ # navigation_toolbar.wait_until_gone(5)
543
+ #
544
+ def wait_until_gone(seconds = nil)
545
+ timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
546
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout)
547
+ wait.until { !exists? }
548
+ rescue
549
+ raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if exists?
550
+ end
551
+
552
+ # Wait until the Section object is visible, or until the specified wait time has expired.
553
+ #
554
+ # @param seconds [Integer or Float] wait time in seconds
555
+ # @example
556
+ # bar_chart_section.wait_until_visible(0.5)
557
+ #
558
+ def wait_until_visible(seconds = nil)
559
+ timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
560
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout)
561
+ wait.until { visible? }
562
+ rescue
563
+ raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless visible?
564
+ end
565
+
566
+ # Wait until the Section object is hidden, or until the specified wait time has expired.
567
+ #
568
+ # @param seconds [Integer or Float] wait time in seconds
569
+ # @example
570
+ # bar_chart_section.wait_until_hidden(10)
571
+ #
572
+ def wait_until_hidden(seconds = nil)
573
+ timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
574
+ wait = Selenium::WebDriver::Wait.new(timeout: timeout)
575
+ wait.until { hidden? }
576
+ rescue
577
+ raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if visible?
578
+ end
579
+
580
+ # Click at a specific location within a Section object
581
+ #
582
+ # @param x [Integer] X offset
583
+ # @param y [Integer] Y offset
584
+ # @example
585
+ # bar_chart_section.click_at(10, 10)
586
+ #
587
+ def click_at(x, y)
588
+ section, = find_section
589
+ raise "Section object '#{get_name}' (#{get_locator}) not found" unless section
590
+ section.click_at(x, y)
591
+ end
592
+
593
+ def verify_ui_states(ui_states)
594
+ ui_states.each do |ui_object, object_states|
595
+ object_states.each do |property, state|
596
+ case property
597
+ when :class
598
+ actual = ui_object.get_attribute(:class)
599
+ when :exists
600
+ actual = ui_object.exists?
601
+ when :enabled
602
+ actual = ui_object.enabled?
603
+ when :disabled
604
+ actual = ui_object.disabled?
605
+ when :visible
606
+ actual = ui_object.visible?
607
+ when :hidden
608
+ actual = ui_object.hidden?
609
+ when :width
610
+ actual = ui_object.get_width
611
+ when :height
612
+ actual = ui_object.get_height
613
+ when :readonly
614
+ actual = ui_object.read_only?
615
+ when :checked
616
+ actual = ui_object.checked?
617
+ when :selected
618
+ actual = ui_object.selected?
619
+ when :value, :caption
620
+ actual = ui_object.get_value
621
+ when :maxlength
622
+ actual = ui_object.get_max_length
623
+ when :rowcount
624
+ actual = ui_object.get_row_count
625
+ when :columncount
626
+ actual = ui_object.get_column_count
627
+ when :placeholder
628
+ actual = ui_object.get_placeholder
629
+ when :min
630
+ actual = ui_object.get_min
631
+ when :max
632
+ actual = ui_object.get_max
633
+ when :step
634
+ actual = ui_object.get_step
635
+ when :options, :items, :list_items
636
+ actual = ui_object.get_list_items
637
+ when :optioncount, :itemcount
638
+ actual = ui_object.get_item_count
639
+ when :column_headers
640
+ actual = ui_object.get_header_columns
641
+ when :siebel_options
642
+ actual = ui_object.get_siebel_options
643
+ else
644
+ if property.is_a?(Hash)
645
+ property.each do |key, value|
646
+ case key
647
+ when :cell
648
+ actual = ui_object.get_table_cell(value[0].to_i, value[1].to_i)
649
+ when :row
650
+ actual = ui_object.get_table_row(value.to_i)
651
+ when :column
652
+ actual = ui_object.get_table_column(value.to_i)
653
+ when :item
654
+ actual = ui_object.get_list_item(value.to_i)
655
+ when :attribute
656
+ actual = ui_object.get_attribute(value)
657
+ when :native_attribute
658
+ actual = ui_object.get_native_attribute(value)
659
+ end
660
+ end
661
+ else
662
+ props = property.to_s.split('_')
663
+ case props[0].to_sym
664
+ when :cell
665
+ cell = property.to_s.delete('cell_')
666
+ cell = cell.split('_')
667
+ actual = ui_object.get_table_cell(cell[0].to_i, cell[1].to_i)
668
+ when :row
669
+ row = property.to_s.delete('row_')
670
+ actual = ui_object.get_table_row(row.to_i)
671
+ when :column
672
+ column = property.to_s.delete('column_')
673
+ actual = ui_object.get_table_column(column.to_i)
674
+ when :item
675
+ item = property.to_s.delete('item_')
676
+ actual = ui_object.get_list_item(item.to_i)
677
+ end
678
+ end
679
+ end
680
+
681
+ if state.is_a?(Hash) && state.length == 1
682
+ error_msg = "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property to"
683
+ state.each do |key, value|
684
+ case key
685
+ when :lt, :less_than
686
+ ExceptionQueue.enqueue_exception("#{error_msg} be less than #{value} but found '#{actual}'") unless actual < value
687
+ when :lt_eq, :less_than_or_equal
688
+ ExceptionQueue.enqueue_exception("#{error_msg} be less than or equal to #{value} but found '#{actual}'") unless actual <= value
689
+ when :gt, :greater_than
690
+ ExceptionQueue.enqueue_exception("#{error_msg} be greater than #{value} but found '#{actual}'") unless actual > value
691
+ when :gt_eq, :greater_than_or_equal
692
+ ExceptionQueue.enqueue_exception("#{error_msg} be greater than or equal to #{value} but found '#{actual}'") unless actual >= value
693
+ when :starts_with
694
+ ExceptionQueue.enqueue_exception("#{error_msg} start with '#{value}' but found '#{actual}'") unless actual.start_with?(value)
695
+ when :ends_with
696
+ ExceptionQueue.enqueue_exception("#{error_msg} end with '#{value}' but found '#{actual}'") unless actual.end_with?(value)
697
+ when :contains
698
+ ExceptionQueue.enqueue_exception("#{error_msg} contain '#{value}' but found '#{actual}'") unless actual.include?(value)
699
+ when :not_contains, :does_not_contain
700
+ ExceptionQueue.enqueue_exception("#{error_msg} not contain '#{value}' but found '#{actual}'") if actual.include?(value)
701
+ when :not_equal
702
+ ExceptionQueue.enqueue_exception("#{error_msg} not equal '#{value}' but found '#{actual}'") if actual == value
703
+ when :like, :is_like
704
+ actual_like = actual.delete("\n")
705
+ actual_like = actual_like.delete("\r")
706
+ actual_like = actual_like.delete("\t")
707
+ actual_like = actual_like.delete(' ')
708
+ actual_like = actual_like.downcase
709
+ expected = value.delete("\n")
710
+ expected = expected.delete("\r")
711
+ expected = expected.delete("\t")
712
+ expected = expected.delete(' ')
713
+ expected = expected.downcase
714
+ ExceptionQueue.enqueue_exception("#{error_msg} be like '#{value}' but found '#{actual}'") unless actual_like.include?(expected)
715
+ when :translate
716
+ expected = I18n.t(value)
717
+ ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) translated #{property} property")
718
+ end
719
+ end
720
+ else
721
+ ExceptionQueue.enqueue_assert_equal(state, actual, "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property")
722
+ end
723
+ end
724
+ end
725
+ ExceptionQueue.post_exceptions
726
+ end
727
+
728
+ # Populate the specified UI elements in this Section object with the associated data from a Hash passed as an
729
+ # argument. Data values must be in the form of a String for textfield and select list controls. For checkbox
730
+ # and radio buttons, data must either be a Boolean or a String that evaluates to a Boolean value (Yes, No, 1,
731
+ # 0, true, false).
732
+ #
733
+ # To delete all text content in a text field, pass !DELETE as the data to be entered.
734
+ #
735
+ # @param data [Hash] UI element(s) and associated data to be entered
736
+ # @example
737
+ # data = { prefix_select => 'Mr.',
738
+ # first_name_field => 'Ignatious',
739
+ # last_name_field => 'Snickelfritz',
740
+ # gender_select => 'Male',
741
+ # dob_field => '12/14/1957',
742
+ # organ_donor_check => 'Yes',
743
+ # dnr_on_file_check => 'Yes'
744
+ # }
745
+ # populate_data_fields(data)
746
+ #
747
+ def populate_data_fields(data)
748
+ data.each do |data_field, data_param|
749
+ unless data_param.blank?
750
+ # make sure the intended UI target element exists before trying to set its value
751
+ data_field.wait_until_exists(2)
752
+ if data_param == '!DELETE'
753
+ length = data_field.get_value.length
754
+ length.times do
755
+ data_field.send_keys(:backspace)
756
+ end
757
+ sleep(0.5)
758
+ data_field.send_keys(:tab)
759
+ else
760
+ case data_field.get_object_type
761
+ when :checkbox
762
+ data_field.set_checkbox_state(data_param.to_bool)
763
+ when :selectlist
764
+ data_field.get_siebel_object_type == 'JComboBox' ?
765
+ data_field.set("#{data_param}\t") :
766
+ data_field.choose_option(data_param)
767
+ when :radio
768
+ data_field.set_selected_state(data_param.to_bool)
769
+ when :textfield
770
+ data_field.set("#{data_param}\t")
771
+ when :section
772
+ data_field.set(data_param)
773
+ end
774
+ end
775
+ end
776
+ end
777
+ end
778
+
779
+ def get_attribute(attrib)
780
+ section, = find_section
781
+ raise "Section object '#{get_name}' (#{get_locator}) not found" unless section
782
+ section[attrib]
783
+ end
784
+
785
+ def get_native_attribute(attrib)
786
+ section, = find_section
787
+ raise "Section object '#{get_name}' (#{get_locator}) not found" unless section
788
+ section.native.attribute(attrib)
789
+ end
790
+
791
+ private
792
+
793
+ def find_section
794
+ locator = get_locator
795
+ tries ||= 2
796
+ attributes = [:id, :xpath, :css]
797
+ type = attributes[tries]
798
+ case type
799
+ when :css
800
+ locator = locator.delete('|')
801
+ when :xpath
802
+ locator = locator.delete('|')
803
+ end
804
+ obj = page.find(type, locator, :wait => 0.1)
805
+ [obj, type]
806
+ rescue
807
+ retry if (tries -= 1) > 0
808
+ [nil, nil]
809
+ end
810
+ end
811
+ end