testcentricity 2.4.3 → 3.0.2

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