testcentricity 2.4.1 → 3.0.0

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 (127) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +29 -0
  3. data/.rspec +2 -1
  4. data/.rubocop.yml +38 -0
  5. data/.ruby-version +1 -1
  6. data/.simplecov +9 -0
  7. data/.yardopts +3 -0
  8. data/CHANGELOG.md +275 -0
  9. data/CODE_OF_CONDUCT.md +13 -0
  10. data/{LICENSE.txt → LICENSE.md} +3 -4
  11. data/README.md +938 -1378
  12. data/Rakefile +63 -1
  13. data/config/cucumber.yml +145 -0
  14. data/config/locales/en-US.yml +56 -0
  15. data/config/test_data/LOCAL_data.yml +11 -0
  16. data/config/test_data/data.yml +10 -0
  17. data/features/deep_links.feature +26 -0
  18. data/features/login.feature +30 -0
  19. data/features/navigation.feature +31 -0
  20. data/features/step_definitions/generic_steps.rb +72 -0
  21. data/features/support/android/screens/about_screen.rb +11 -0
  22. data/features/support/android/screens/base_app_screen.rb +29 -0
  23. data/features/support/android/screens/checkout_address_screen.rb +17 -0
  24. data/features/support/android/screens/checkout_payment_screen.rb +22 -0
  25. data/features/support/android/screens/login_screen.rb +18 -0
  26. data/features/support/android/screens/products_screen.rb +13 -0
  27. data/features/support/android/screens/saucebot_screen.rb +16 -0
  28. data/features/support/android/screens/webview_screen.rb +13 -0
  29. data/features/support/android/sections/nav_widgets/nav_menu.rb +39 -0
  30. data/features/support/env.rb +61 -0
  31. data/features/support/hooks.rb +135 -0
  32. data/features/support/ios/screens/about_screen.rb +11 -0
  33. data/features/support/ios/screens/base_app_screen.rb +19 -0
  34. data/features/support/ios/screens/checkout_address_screen.rb +17 -0
  35. data/features/support/ios/screens/checkout_payment_screen.rb +22 -0
  36. data/features/support/ios/screens/login_screen.rb +18 -0
  37. data/features/support/ios/screens/products_screen.rb +13 -0
  38. data/features/support/ios/screens/saucebot_screen.rb +16 -0
  39. data/features/support/ios/screens/webview_screen.rb +13 -0
  40. data/features/support/ios/sections/list_items/product_cell_item.rb +13 -0
  41. data/features/support/ios/sections/modals/base_modal.rb +23 -0
  42. data/features/support/ios/sections/modals/logout_modal.rb +6 -0
  43. data/features/support/ios/sections/modals/reset_app_state_modal.rb +6 -0
  44. data/features/support/ios/sections/nav_widgets/nav_bar.rb +31 -0
  45. data/features/support/ios/sections/nav_widgets/nav_menu.rb +41 -0
  46. data/features/support/shared_components/screens/base_app_screen.rb +31 -0
  47. data/features/support/shared_components/screens/checkout_address_screen.rb +17 -0
  48. data/features/support/shared_components/screens/checkout_payment_screen.rb +22 -0
  49. data/features/support/shared_components/screens/login_screen.rb +39 -0
  50. data/features/support/shared_components/screens/saucebot_screen.rb +17 -0
  51. data/features/support/shared_components/screens/webview_screen.rb +12 -0
  52. data/features/support/shared_components/sections/nav_menu.rb +58 -0
  53. data/features/support/world_data.rb +12 -0
  54. data/features/support/world_pages.rb +26 -0
  55. data/lib/testcentricity/app_core/appium_connect_helper.rb +355 -111
  56. data/lib/testcentricity/app_core/screen_object.rb +252 -0
  57. data/lib/testcentricity/app_core/screen_objects_helper.rb +29 -280
  58. data/lib/testcentricity/app_core/screen_section.rb +350 -0
  59. data/lib/testcentricity/app_elements/app_element_helper.rb +17 -8
  60. data/lib/testcentricity/app_elements/checkbox.rb +3 -3
  61. data/lib/testcentricity/data_objects/environment.rb +133 -39
  62. data/lib/testcentricity/version.rb +1 -1
  63. data/lib/testcentricity.rb +4 -129
  64. data/reports/.keep +1 -0
  65. data/spec/fixtures/page_object.rb +22 -0
  66. data/spec/fixtures/page_section_object.rb +21 -0
  67. data/spec/fixtures/screen_object.rb +16 -0
  68. data/spec/fixtures/screen_section_object.rb +16 -0
  69. data/spec/spec_helper.rb +28 -9
  70. data/spec/testcentricity/elements/button_spec.rb +18 -0
  71. data/spec/testcentricity/elements/checkbox_spec.rb +28 -0
  72. data/spec/testcentricity/elements/image_spec.rb +13 -0
  73. data/spec/testcentricity/elements/label_spec.rb +18 -0
  74. data/spec/testcentricity/elements/list_spec.rb +13 -0
  75. data/spec/testcentricity/elements/ui_element_spec.rb +72 -0
  76. data/spec/testcentricity/mobile/appium_connect_spec.rb +117 -0
  77. data/spec/testcentricity/mobile/screen_object_spec.rb +63 -0
  78. data/spec/testcentricity/mobile/screen_section_object_spec.rb +56 -0
  79. data/spec/testcentricity/version_spec.rb +7 -0
  80. data/spec/testcentricity/web/browser_spec.rb +41 -0
  81. data/spec/testcentricity/web/local_webdriver_spec.rb +86 -0
  82. data/spec/testcentricity/web/mobile_webdriver_spec.rb +123 -0
  83. data/spec/testcentricity/web/page_object_spec.rb +85 -0
  84. data/spec/testcentricity/web/page_section_object_spec.rb +72 -0
  85. data/testcentricity.gemspec +28 -27
  86. metadata +196 -127
  87. data/.ruby-gemset +0 -1
  88. data/Gemfile.lock +0 -93
  89. data/bin/console +0 -14
  90. data/bin/setup +0 -8
  91. data/lib/devices/devices.yml +0 -352
  92. data/lib/testcentricity/app_core/appium_server.rb +0 -69
  93. data/lib/testcentricity/app_core/screen_sections_helper.rb +0 -491
  94. data/lib/testcentricity/browser_helper.rb +0 -174
  95. data/lib/testcentricity/data_objects/data_objects_helper.rb +0 -78
  96. data/lib/testcentricity/data_objects/excel_helper.rb +0 -242
  97. data/lib/testcentricity/exception_queue_helper.rb +0 -111
  98. data/lib/testcentricity/utility_helpers.rb +0 -28
  99. data/lib/testcentricity/web_core/drag_drop_helper.rb +0 -15
  100. data/lib/testcentricity/web_core/page_objects_helper.rb +0 -711
  101. data/lib/testcentricity/web_core/page_sections_helper.rb +0 -932
  102. data/lib/testcentricity/web_core/webdriver_helper.rb +0 -588
  103. data/lib/testcentricity/web_elements/button.rb +0 -8
  104. data/lib/testcentricity/web_elements/cell_button.rb +0 -8
  105. data/lib/testcentricity/web_elements/cell_checkbox.rb +0 -38
  106. data/lib/testcentricity/web_elements/cell_element.rb +0 -69
  107. data/lib/testcentricity/web_elements/cell_image.rb +0 -8
  108. data/lib/testcentricity/web_elements/cell_radio.rb +0 -31
  109. data/lib/testcentricity/web_elements/checkbox.rb +0 -100
  110. data/lib/testcentricity/web_elements/file_field.rb +0 -45
  111. data/lib/testcentricity/web_elements/image.rb +0 -34
  112. data/lib/testcentricity/web_elements/label.rb +0 -8
  113. data/lib/testcentricity/web_elements/link.rb +0 -8
  114. data/lib/testcentricity/web_elements/list.rb +0 -100
  115. data/lib/testcentricity/web_elements/list_button.rb +0 -8
  116. data/lib/testcentricity/web_elements/list_checkbox.rb +0 -38
  117. data/lib/testcentricity/web_elements/list_element.rb +0 -61
  118. data/lib/testcentricity/web_elements/list_radio.rb +0 -31
  119. data/lib/testcentricity/web_elements/radio.rb +0 -74
  120. data/lib/testcentricity/web_elements/select_list.rb +0 -208
  121. data/lib/testcentricity/web_elements/siebel_open_ui_helper.rb +0 -15
  122. data/lib/testcentricity/web_elements/table.rb +0 -612
  123. data/lib/testcentricity/web_elements/textfield.rb +0 -114
  124. data/lib/testcentricity/web_elements/ui_elements_helper.rb +0 -532
  125. data/lib/testcentricity/world_extensions.rb +0 -26
  126. data/my_templates/default/method_details/setup.rb +0 -3
  127. data/spec/testcentricity_spec.rb +0 -9
@@ -1,711 +0,0 @@
1
- require 'test/unit'
2
-
3
- module TestCentricity
4
- class PageObject
5
- include Capybara::DSL
6
- include Capybara::Node::Matchers
7
- include Test::Unit::Assertions
8
-
9
- # Define a trait for this page object.
10
- #
11
- # @param trait_name [Symbol] name of trait (as a symbol)
12
- # @param block [&block] trait value
13
- # @example
14
- # trait(:page_name) { 'Shopping Basket' }
15
- # trait(:page_url) { '/shopping_basket' }
16
- # trait(:page_locator) { "//body[@class='shopping_baskets']" }
17
- #
18
- def self.trait(trait_name, &block)
19
- define_method(trait_name.to_s, &block)
20
- end
21
-
22
- # Declare and instantiate a single generic UI Element for this page object.
23
- #
24
- # @param element_name [Symbol] name of UI object (as a symbol)
25
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
26
- # @example
27
- # element :siebel_view, 'div#_sweview'
28
- # element :siebel_busy, "//html[contains(@class, 'siebui-busy')]"
29
- #
30
- def self.element(element_name, locator)
31
- define_method(element_name) do
32
- ivar_name = "@#{element_name}"
33
- ivar = instance_variable_get(ivar_name)
34
- return ivar if ivar
35
- instance_variable_set(ivar_name, TestCentricity::UIElement.new(element_name, self, locator, :page))
36
- end
37
- end
38
-
39
- # Declare and instantiate a collection of generic UI Elements for this page object.
40
- #
41
- # @param element_hash [Hash] names of UI objects (as a symbol) and CSS selectors or XPath expressions that uniquely identifies objects
42
- # @example
43
- # elements profile_item: 'a#profile',
44
- # settings_item: 'a#userPreferencesTrigger',
45
- # log_out_item: 'a#logout'
46
- #
47
- def self.elements(element_hash)
48
- element_hash.each do |element_name, locator|
49
- element(element_name, locator)
50
- end
51
- end
52
-
53
- # Declare and instantiate a single button UI Element for this page object.
54
- #
55
- # @param element_name [Symbol] name of button object (as a symbol)
56
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
57
- # @example
58
- # button :checkout_button, 'button.checkout_button'
59
- # button :login_button, "//input[@id='submit_button']"
60
- #
61
- def self.button(element_name, locator)
62
- define_method(element_name) do
63
- ivar_name = "@#{element_name}"
64
- ivar = instance_variable_get(ivar_name)
65
- return ivar if ivar
66
- instance_variable_set(ivar_name, TestCentricity::Button.new(element_name, self, locator, :page))
67
- end
68
- end
69
-
70
- # Declare and instantiate a collection of buttons for this page object.
71
- #
72
- # @param element_hash [Hash] names of buttons (as a symbol) and CSS selectors or XPath expressions that uniquely identifies buttons
73
- # @example
74
- # buttons new_account_button: 'button#new-account',
75
- # save_button: 'button#save',
76
- # cancel_button: 'button#cancel'
77
- #
78
- def self.buttons(element_hash)
79
- element_hash.each do |element_name, locator|
80
- button(element_name, locator)
81
- end
82
- end
83
-
84
- # Declare and instantiate a single text field UI Element for this page object.
85
- #
86
- # @param element_name [Symbol] name of text field object (as a symbol)
87
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
88
- # @example
89
- # textfield :user_id_field, "//input[@id='UserName']"
90
- # textfield :password_field, 'consumer_password'
91
- #
92
- def self.textfield(element_name, locator)
93
- define_method(element_name) do
94
- ivar_name = "@#{element_name}"
95
- ivar = instance_variable_get(ivar_name)
96
- return ivar if ivar
97
- instance_variable_set(ivar_name, TestCentricity::TextField.new(element_name, self, locator, :page))
98
- end
99
- end
100
-
101
- # Declare and instantiate a collection of text fields for this page object.
102
- #
103
- # @param element_hash [Hash] names of text fields (as a symbol) and CSS selectors or XPath expressions that uniquely identifies text fields
104
- # @example
105
- # textfields name_field: 'input#Name',
106
- # title_field: 'input#Title',
107
- # phone_field: 'input#PhoneNumber',
108
- # fax_field: 'input#FaxNumber',
109
- # email_field: 'input#Email'
110
- #
111
- def self.textfields(element_hash)
112
- element_hash.each do |element_name, locator|
113
- textfield(element_name, locator)
114
- end
115
- end
116
-
117
- # Declare and instantiate a single checkbox UI Element for this page object.
118
- #
119
- # @param element_name [Symbol] name of checkbox object (as a symbol)
120
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
121
- # @param proxy [Symbol] Optional name (as a symbol) of proxy object to receive click actions
122
- # @example
123
- # checkbox :remember_checkbox, "//input[@id='RememberUser']"
124
- # checkbox :accept_terms_checkbox, 'input#accept_terms_conditions', :accept_terms_label
125
- #
126
- def self.checkbox(element_name, locator, proxy = nil)
127
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CheckBox.new("#{element_name}", self, "#{locator}", :page, #{proxy});end))
128
- end
129
-
130
- # Declare and instantiate a collection of checkboxes for this page object.
131
- #
132
- # @param element_hash [Hash] names of checkboxes (as a symbol) and CSS selectors or XPath expressions that uniquely identifies checkboxes
133
- # @example
134
- # checkboxes hazmat_certified_check: 'input#hazmatCertified',
135
- # epa_certified_check: 'input#epaCertified',
136
- # dhs_certified_check: 'input#homelandSecurityCertified',
137
- # carb_compliant_check: 'input#carbCompliant'
138
- #
139
- def self.checkboxes(element_hash)
140
- element_hash.each do |element_name, locator|
141
- checkbox(element_name, locator)
142
- end
143
- end
144
-
145
- # Declare and instantiate a single radio button UI Element for this page object.
146
- #
147
- # @param element_name [Symbol] name of radio object (as a symbol)
148
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
149
- # @param proxy [Symbol] Optional name (as a symbol) of proxy object to receive click actions
150
- # @example
151
- # radio :accept_terms_radio, "//input[@id='Accept_Terms']"
152
- # radio :decline_terms_radio, '#decline_terms_conditions', :decline_terms_label
153
- #
154
- def self.radio(element_name, locator, proxy = nil)
155
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::Radio.new("#{element_name}", self, "#{locator}", :page, #{proxy});end))
156
- end
157
-
158
- # Declare and instantiate a collection of radio buttons for this page object.
159
- #
160
- # @param element_hash [Hash] names of radio buttons (as a symbol) and CSS selectors or XPath expressions that uniquely identifies radio buttons
161
- # @example
162
- # radios visa_radio: 'input#payWithVisa',
163
- # mastercard_radio: 'input#payWithMastercard',
164
- # discover_radio: 'input#payWithDiscover',
165
- # amex_radio: 'input#payWithAmEx'
166
- #
167
- def self.radios(element_hash)
168
- element_hash.each do |element_name, locator|
169
- radio(element_name, locator)
170
- end
171
- end
172
-
173
- # Declare and instantiate a single label UI Element for this page object.
174
- #
175
- # @param element_name [Symbol] name of label object (as a symbol)
176
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
177
- # @example
178
- # label :welcome_label, 'div.Welcome'
179
- # label :rollup_price_label, "//div[contains(@id, 'Rollup Item Price')]"
180
- #
181
- def self.label(element_name, locator)
182
- define_method(element_name) do
183
- ivar_name = "@#{element_name}"
184
- ivar = instance_variable_get(ivar_name)
185
- return ivar if ivar
186
- instance_variable_set(ivar_name, TestCentricity::Label.new(element_name, self, locator, :page))
187
- end
188
- end
189
-
190
- def self.labels(element_hash)
191
- element_hash.each do |element_name, locator|
192
- label(element_name, locator)
193
- end
194
- end
195
-
196
- # Declare and instantiate a single link UI Element for this page object.
197
- #
198
- # @param element_name [Symbol] name of link object (as a symbol)
199
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
200
- # @example
201
- # link :registration_link, 'a.account-nav__link.register'
202
- # link :shopping_basket_link, "//a[@href='shopping_basket']"
203
- #
204
- def self.link(element_name, locator)
205
- define_method(element_name) do
206
- ivar_name = "@#{element_name}"
207
- ivar = instance_variable_get(ivar_name)
208
- return ivar if ivar
209
- instance_variable_set(ivar_name, TestCentricity::Link.new(element_name, self, locator, :page))
210
- end
211
- end
212
-
213
- def self.links(element_hash)
214
- element_hash.each do |element_name, locator|
215
- link(element_name, locator)
216
- end
217
- end
218
-
219
- # Declare and instantiate a single table UI Element for this page object.
220
- #
221
- # @param element_name [Symbol] name of table object (as a symbol)
222
- # @param locator [String] XPath expression that uniquely identifies object
223
- # @example
224
- # table :payments_table, "//table[@class='payments_table']"
225
- #
226
- def self.table(element_name, locator)
227
- define_method(element_name) do
228
- ivar_name = "@#{element_name}"
229
- ivar = instance_variable_get(ivar_name)
230
- return ivar if ivar
231
- instance_variable_set(ivar_name, TestCentricity::Table.new(element_name, self, locator, :page))
232
- end
233
- end
234
-
235
- def self.tables(element_hash)
236
- element_hash.each do |element_name, locator|
237
- table(element_name, locator)
238
- end
239
- end
240
-
241
- # Declare and instantiate a single select list UI Element for this page object.
242
- #
243
- # @param element_name [Symbol] name of select list object (as a symbol)
244
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
245
- # @example
246
- # selectlist :category_selector, 'select#search_form_category_chosen'
247
- # selectlist :gender_select, "//select[@id='customer_gender']"
248
- #
249
- def self.selectlist(element_name, locator)
250
- define_method(element_name) do
251
- ivar_name = "@#{element_name}"
252
- ivar = instance_variable_get(ivar_name)
253
- return ivar if ivar
254
- instance_variable_set(ivar_name, TestCentricity::SelectList.new(element_name, self, locator, :page))
255
- end
256
- end
257
-
258
- def self.selectlists(element_hash)
259
- element_hash.each do |element_name, locator|
260
- selectlist(element_name, locator)
261
- end
262
- end
263
-
264
- # Declare and instantiate a single list UI Element for this page object.
265
- #
266
- # @param element_name [Symbol] name of list object (as a symbol)
267
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
268
- # @example
269
- # list :x_axis_list, 'g.x-axis'
270
- #
271
- def self.list(element_name, locator)
272
- define_method(element_name) do
273
- ivar_name = "@#{element_name}"
274
- ivar = instance_variable_get(ivar_name)
275
- return ivar if ivar
276
- instance_variable_set(ivar_name, TestCentricity::List.new(element_name, self, locator, :page))
277
- end
278
- end
279
-
280
- def self.lists(element_hash)
281
- element_hash.each do |element_name, locator|
282
- list(element_name, locator)
283
- end
284
- end
285
-
286
- # Declare and instantiate an single image UI Element for this page object.
287
- #
288
- # @param element_name [Symbol] name of image object (as a symbol)
289
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
290
- # @example
291
- # image :basket_item_image, 'div.product_image'
292
- # image :corporate_logo_image, "//img[@alt='MyCompany_logo']"
293
- #
294
- def self.image(element_name, locator)
295
- define_method(element_name) do
296
- ivar_name = "@#{element_name}"
297
- ivar = instance_variable_get(ivar_name)
298
- return ivar if ivar
299
- instance_variable_set(ivar_name, TestCentricity::Image.new(element_name, self, locator, :page))
300
- end
301
- end
302
-
303
- def self.images(element_hash)
304
- element_hash.each do |element_name, locator|
305
- image(element_name, locator)
306
- end
307
- end
308
-
309
- # Declare and instantiate a single File Field UI Element for this page object.
310
- #
311
- # @param element_name [Symbol] name of file field object (as a symbol)
312
- # @param locator [String] CSS selector or XPath expression that uniquely identifies object
313
- # @example
314
- # filefield :attach_file, 's_SweFileName'
315
- #
316
- def self.filefield(element_name, locator)
317
- define_method(element_name) do
318
- ivar_name = "@#{element_name}"
319
- ivar = instance_variable_get(ivar_name)
320
- return ivar if ivar
321
- instance_variable_set(ivar_name, TestCentricity::FileField.new(element_name, self, locator, :page))
322
- end
323
- end
324
-
325
- def self.filefields(element_hash)
326
- element_hash.each do |element_name, locator|
327
- filefield(element_name, locator)
328
- end
329
- end
330
-
331
- # Declare and instantiate a cell button in a table column on this page object.
332
- #
333
- # @param element_name [Symbol] name of cell button object (as a symbol)
334
- # @param locator [String] XPath expression that uniquely identifies cell button within row and column of parent table object
335
- # @param table [Symbol] Name (as a symbol) of parent table object
336
- # @param column [Integer] 1-based index of table column that contains the cell button object
337
- # @example
338
- # cell_button :show_button, "a[@class='show']", :data_table, 5
339
- # cell_button :edit_button, "a[@class='edit']", :data_table, 5
340
- #
341
- def self.cell_button(element_name, locator, table, column)
342
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellButton.new("#{element_name}", self, "#{locator}", :page, #{table}, #{column});end))
343
- end
344
-
345
- # Declare and instantiate a cell checkbox in a table column on this page object.
346
- #
347
- # @param element_name [Symbol] name of cell checkbox object (as a symbol)
348
- # @param locator [String] XPath expression that uniquely identifies cell checkbox within row and column of parent table object
349
- # @param table [Symbol] Name (as a symbol) of parent table object
350
- # @param column [Integer] 1-based index of table column that contains the cell checkbox object
351
- # @example
352
- # cell_checkbox :is_registered_check, "a[@class='registered']", :data_table, 4
353
- #
354
- def self.cell_checkbox(element_name, locator, table, column, proxy = nil)
355
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellCheckBox.new("#{element_name}", self, "#{locator}", :page, #{table}, #{column}, #{proxy});end))
356
- end
357
-
358
- # Declare and instantiate a cell radio in a table column on this page object.
359
- #
360
- # @param element_name [Symbol] name of cell radio object (as a symbol)
361
- # @param locator [String] XPath expression that uniquely identifies cell radio 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 radio object
364
- # @example
365
- # cell_radio :track_a_radio, "a[@class='track_a']", :data_table, 8
366
- #
367
- def self.cell_radio(element_name, locator, table, column, proxy = nil)
368
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellRadio.new("#{element_name}", self, "#{locator}", :page, #{table}, #{column}, #{proxy});end))
369
- end
370
-
371
- # Declare and instantiate a cell image in a table column on this page object.
372
- #
373
- # @param element_name [Symbol] name of cell image object (as a symbol)
374
- # @param locator [String] XPath expression that uniquely identifies cell image within row and column of parent table object
375
- # @param table [Symbol] Name (as a symbol) of parent table object
376
- # @param column [Integer] 1-based index of table column that contains the cell image object
377
- # @example
378
- # cell_image :ready_icon, "img[@class='ready']", :data_table, 3
379
- # cell_image :send_icon, "img[@class='send']", :data_table, 3
380
- #
381
- def self.cell_image(element_name, locator, table, column)
382
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::CellImage.new("#{element_name}", self, "#{locator}", :page, #{table}, #{column});end))
383
- end
384
-
385
- # Declare and instantiate a list button in a row of a list object on this page object.
386
- #
387
- # @param element_name [Symbol] name of list button object (as a symbol)
388
- # @param locator [String] XPath expression that uniquely identifies list button within row of parent list object
389
- # @param list [Symbol] Name (as a symbol) of parent list object
390
- # @example
391
- # list_button :delete_button, "a[@class='delete']", :icon_list
392
- # list_button :edit_button, "a[@class='edit']", :icon_list
393
- #
394
- def self.list_button(element_name, locator, list)
395
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::ListButton.new("#{element_name}", self, "#{locator}", :page, #{list});end))
396
- end
397
-
398
- # Declare and instantiate a list checkbox in a row of a list object on this page object.
399
- #
400
- # @param element_name [Symbol] name of list checkbox object (as a symbol)
401
- # @param locator [String] XPath expression that uniquely identifies list checkbox within row of parent list object
402
- # @param list [Symbol] Name (as a symbol) of parent list object
403
- # @example
404
- # list_checkbox :is_registered_check, "a[@class='registered']", :data_list
405
- #
406
- def self.list_checkbox(element_name, locator, list, proxy = nil)
407
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::ListCheckBox.new("#{element_name}", self, "#{locator}", :page, #{list}, #{proxy});end))
408
- end
409
-
410
- # Declare and instantiate a list radio in a row of a list object on this page object.
411
- #
412
- # @param element_name [Symbol] name of list radio object (as a symbol)
413
- # @param locator [String] XPath expression that uniquely identifies list radio within row of parent list object
414
- # @param list [Symbol] Name (as a symbol) of parent list object
415
- # @example
416
- # list_radio :sharing_radio, "a[@class='sharing']", :data_list
417
- #
418
- def self.list_radio(element_name, locator, list, proxy = nil)
419
- class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::ListRadio.new("#{element_name}", self, "#{locator}", :page, #{list}, #{proxy});end))
420
- end
421
-
422
- # Instantiate a single PageSection object for this page object.
423
- #
424
- # @param section_name [Symbol] name of PageSection object (as a symbol)
425
- # @param class_name [String] Class name of PageSection object
426
- # @example
427
- # section :search_form, SearchForm
428
- #
429
- def self.section(section_name, class_name, locator = nil)
430
- class_eval(%(def #{section_name};@#{section_name} ||= #{class_name}.new("#{section_name}", self, "#{locator}", :page);end))
431
- end
432
-
433
- def self.sections(section_hash)
434
- section_hash.each do |section_name, class_name|
435
- section(section_name, class_name)
436
- end
437
- end
438
-
439
- def open_portal
440
- environment = Environ.current
441
- environment.hostname.blank? ?
442
- url = "#{environment.base_url}#{environment.append}" :
443
- url = "#{environment.hostname}/#{environment.base_url}#{environment.append}"
444
- if environment.user_id.blank? || environment.password.blank?
445
- visit "#{environment.protocol}://#{url}"
446
- else
447
- visit "#{environment.protocol}://#{environment.user_id}:#{environment.password}@#{url}"
448
- end
449
- Environ.portal_state = :open
450
- end
451
-
452
- def verify_page_exists
453
- raise "Page object #{self.class.name} does not have a page_locator trait defined" unless defined?(page_locator)
454
- unless page.has_selector?(page_locator)
455
- body_class = find(:xpath, '//body')[:class]
456
- error_message = %(
457
- Expected page to have selector '#{page_locator}' but found '#{body_class}' instead.
458
- Actual URL of page loaded = #{URI.parse(current_url)}.
459
- )
460
- error_message = "#{error_message}\nExpected URL of page was #{page_url}." if defined?(page_url)
461
- raise error_message
462
- end
463
- PageManager.current_page = self
464
- end
465
-
466
- def navigate_to; end
467
-
468
- def verify_page_ui; end
469
-
470
- def load_page
471
- return if exists?
472
- if defined?(page_url) && !page_url.nil?
473
- visit page_url
474
- begin
475
- page.driver.browser.switch_to.alert.accept
476
- rescue => e
477
- end unless Environ.browser == :safari || Environ.browser == :ie || Environ.is_device?
478
- else
479
- navigate_to
480
- end
481
- verify_page_exists
482
- end
483
-
484
- def verify_page_contains(content)
485
- raise "Expected page to have content '#{content}'" unless page.has_content?(:visible, content)
486
- end
487
-
488
- # Does Page object exists?
489
- #
490
- # @return [Boolean]
491
- # @example
492
- # home_page.exists?
493
- #
494
- def exists?
495
- raise "Page object #{self.class.name} does not have a page_locator trait defined" unless defined?(page_locator)
496
- saved_wait_time = Capybara.default_max_wait_time
497
- Capybara.default_max_wait_time = 0.1
498
- tries ||= 2
499
- attributes = [:id, :css, :xpath]
500
- type = attributes[tries]
501
- obj = page.find(type, page_locator)
502
- obj != nil
503
- rescue
504
- Capybara.default_max_wait_time = saved_wait_time
505
- retry if (tries -= 1) > 0
506
- false
507
- ensure
508
- Capybara.default_max_wait_time = saved_wait_time
509
- end
510
-
511
- # Wait until the page object exists, or until the specified wait time has expired. If the wait time is nil, then the wait
512
- # time will be Capybara.default_max_wait_time.
513
- #
514
- # @param seconds [Integer or Float] wait time in seconds
515
- # @example
516
- # home_page.wait_until_exists(15)
517
- #
518
- def wait_until_exists(seconds = nil)
519
- timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
520
- wait = Selenium::WebDriver::Wait.new(timeout: timeout)
521
- wait.until { exists? }
522
- rescue
523
- raise "Page object #{self.class.name} not found after #{timeout} seconds" unless exists?
524
- end
525
-
526
- # Wait until the page object no longer exists, or until the specified wait time has expired. If the wait time is nil, then
527
- # the wait time will be Capybara.default_max_wait_time.
528
- #
529
- # @param seconds [Integer or Float] wait time in seconds
530
- # @example
531
- # verifying_page.wait_until_gone(15)
532
- #
533
- def wait_until_gone(seconds = nil)
534
- timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
535
- wait = Selenium::WebDriver::Wait.new(timeout: timeout)
536
- wait.until { !exists? }
537
- rescue
538
- raise "Page object #{self.class.name} remained visible after #{timeout} seconds" if exists?
539
- end
540
-
541
- # Is current Page object URL secure?
542
- #
543
- # @return [Boolean]
544
- # @example
545
- # home_page.secure?
546
- #
547
- def secure?
548
- !current_url.match(/^https/).nil?
549
- end
550
-
551
- def verify_ui_states(ui_states)
552
- ui_states.each do |ui_object, object_states|
553
- object_states.each do |property, state|
554
- case property
555
- when :class
556
- actual = ui_object.get_attribute(:class)
557
- when :exists
558
- actual = ui_object.exists?
559
- when :enabled
560
- actual = ui_object.enabled?
561
- when :disabled
562
- actual = ui_object.disabled?
563
- when :visible
564
- actual = ui_object.visible?
565
- when :hidden
566
- actual = ui_object.hidden?
567
- when :displayed
568
- actual = ui_object.displayed?
569
- when :width
570
- actual = ui_object.width
571
- when :height
572
- actual = ui_object.height
573
- when :x
574
- actual = ui_object.x
575
- when :y
576
- actual = ui_object.y
577
- when :readonly
578
- actual = ui_object.read_only?
579
- when :checked
580
- actual = ui_object.checked?
581
- when :selected
582
- actual = ui_object.selected?
583
- when :value, :caption
584
- actual = ui_object.get_value
585
- when :maxlength
586
- actual = ui_object.get_max_length
587
- when :rowcount
588
- actual = ui_object.get_row_count
589
- when :columncount
590
- actual = ui_object.get_column_count
591
- when :placeholder
592
- actual = ui_object.get_placeholder
593
- when :min
594
- actual = ui_object.get_min
595
- when :max
596
- actual = ui_object.get_max
597
- when :step
598
- actual = ui_object.get_step
599
- when :options, :items, :list_items
600
- actual = ui_object.get_list_items
601
- when :optioncount, :itemcount
602
- actual = ui_object.get_item_count
603
- when :all_items, :all_list_items
604
- actual = ui_object.get_all_list_items
605
- when :all_items_count
606
- actual = ui_object.get_all_items_count
607
- when :column_headers
608
- actual = ui_object.get_header_columns
609
- when :siebel_options
610
- actual = ui_object.get_siebel_options
611
- else
612
- if property.is_a?(Hash)
613
- property.each do |key, value|
614
- case key
615
- when :cell
616
- actual = ui_object.get_table_cell(value[0].to_i, value[1].to_i)
617
- when :row
618
- actual = ui_object.get_table_row(value.to_i)
619
- when :column
620
- actual = ui_object.get_table_column(value.to_i)
621
- when :item
622
- actual = ui_object.get_list_item(value.to_i)
623
- when :attribute
624
- actual = ui_object.get_attribute(value)
625
- when :native_attribute
626
- actual = ui_object.get_native_attribute(value)
627
- end
628
- end
629
- else
630
- props = property.to_s.split('_')
631
- case props[0].to_sym
632
- when :cell
633
- cell = property.to_s.delete('cell_')
634
- cell = cell.split('_')
635
- actual = ui_object.get_table_cell(cell[0].to_i, cell[1].to_i)
636
- when :row
637
- row = property.to_s.delete('row_')
638
- actual = ui_object.get_table_row(row.to_i)
639
- when :column
640
- column = property.to_s.delete('column_')
641
- actual = ui_object.get_table_column(column.to_i)
642
- when :item
643
- item = property.to_s.delete('item_')
644
- actual = ui_object.get_list_item(item.to_i)
645
- end
646
- end
647
- end
648
- error_msg = "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property to"
649
- ExceptionQueue.enqueue_comparison(state, actual, error_msg)
650
- end
651
- end
652
- rescue ObjectNotFoundError => e
653
- ExceptionQueue.enqueue_exception(e.message)
654
- ensure
655
- ExceptionQueue.post_exceptions
656
- end
657
-
658
- # Populate the specified UI elements on this page with the associated data from a Hash passed as an argument. Data
659
- # values must be in the form of a String for textfield and select list controls. For checkbox and radio buttons,
660
- # data must either be a Boolean or a String that evaluates to a Boolean value (Yes, No, 1, 0, true, false).
661
- #
662
- # The optional wait_time parameter is used to specify the time (in seconds) to wait for each UI element to become
663
- # visible before entering the associated data value. This option is useful in situations where entering data, or
664
- # setting the state of a UI element might cause other UI elements to become visible or active. Specifying a wait_time
665
- # value ensures that the subsequent UI elements will be ready to be interacted with as states are changed. If the wait
666
- # time is nil, then the wait time will be 5 seconds.
667
- #
668
- # To delete all text content in a text field, pass !DELETE as the data to be entered.
669
- #
670
- # @param data [Hash] UI element(s) and associated data to be entered
671
- # @param wait_time [Integer] wait time in seconds
672
- # @example
673
- # field_data = { prefix_select => 'Ms',
674
- # first_name_field => 'Priscilla',
675
- # last_name_field => 'Pumperknickle',
676
- # gender_select => 'Female',
677
- # dob_field => '11/18/1976',
678
- # email_field => 'p.pumperknickle4876@gmail.com',
679
- # mailing_list_check => 'Yes'
680
- # }
681
- # populate_data_fields(field_data)
682
- #
683
- def populate_data_fields(data, wait_time = nil)
684
- timeout = wait_time.nil? ? 5 : wait_time
685
- data.each do |data_field, data_param|
686
- unless data_param.blank?
687
- # make sure the intended UI target element is visible before trying to set its value
688
- data_field.wait_until_visible(timeout)
689
- if data_param == '!DELETE'
690
- data_field.clear
691
- else
692
- case data_field.get_object_type
693
- when :checkbox
694
- data_field.set_checkbox_state(data_param.to_bool)
695
- when :selectlist
696
- data_field.get_siebel_object_type == 'JComboBox' ?
697
- data_field.set("#{data_param}\t") :
698
- data_field.choose_option(data_param)
699
- when :radio
700
- data_field.set_selected_state(data_param.to_bool)
701
- when :textfield
702
- data_field.set("#{data_param}\t")
703
- when :section
704
- data_field.set(data_param)
705
- end
706
- end
707
- end
708
- end
709
- end
710
- end
711
- end