testcentricity_web 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efa2ac57acd9db62cb902913e7b5d01f2fc0da1c
4
- data.tar.gz: fdc2c928d12c6d36deb09479097f1ed503e6bdca
3
+ metadata.gz: e3a4df3b5ec1ff539aa075b22f539bfad13343ae
4
+ data.tar.gz: cb44ead5d3e54df4474f17d79452949ed21b7ca1
5
5
  SHA512:
6
- metadata.gz: 80070a049f3ebe5bff203c2778d615cadd5a54de75d40e8efb7ec6d6be8cc3ac0a3714ab52db6be88228996554a6a2e68bc7ae141fe1303238b36c0e54733a86
7
- data.tar.gz: 056732a64b5a80bbc88d4437424c260a951756ab83c2c257f6b1447d2d44289e247c3f2815c670950321c6b30eec09b2b59ad591dcb93fd31dce702a17895554
6
+ metadata.gz: 4a7f722564956db3ea58c2abe9cbb0ea5eafba23aa557a3004730a6938c41f73b389419bbe54f8c6818167d8b281aee18e7ec72a2d5dd3ddb8159defa24ada65
7
+ data.tar.gz: eaf26e88a4fceb2242f79d835e13131809504d3d9009857f95c71cdcbe32b7778a7067f2f8e29f94a08fd3eda3603e043db28a6403e2dc2889121d5bba94695b
data/README.md CHANGED
@@ -120,11 +120,11 @@ You define your page's **Traits** as shown below:
120
120
  trait(:page_locator) { "//body[@class='login-body']" }
121
121
 
122
122
  # Login page UI elements
123
- textfield :user_id_field, "userName"
124
- textfield :password_field, "password"
125
- button :login_button, "//input[@id='submit_button']"
126
- checkbox :remember_checkbox, "rememberUser']"
127
- label :error_message_label, 'div#statusBar.login-error'
123
+ textfield :user_id_field, "userName"
124
+ textfield :password_field, "password"
125
+ button :login_button, "//input[@id='submit_button']"
126
+ checkbox :remember_checkbox, "rememberUser']"
127
+ label :error_message_label, 'div#statusBar.login-error'
128
128
  end
129
129
 
130
130
  Once your **Page Objects** have been instantiated, you can interact with the **UI Elements** in your **Page Objects**. An example is shown
@@ -147,11 +147,11 @@ the UI to hide implementation details, as shown below:
147
147
  trait(:page_locator) { "//body[@class='login-body']" }
148
148
 
149
149
  # Login page UI elements
150
- textfield :user_id_field, "userName"
151
- textfield :password_field, "password"
152
- button :login_button, "//input[@id='submit_button']"
153
- checkbox :remember_checkbox, "rememberUser']"
154
- label :error_message_label, 'div#statusBar.login-error'
150
+ textfield :user_id_field, "userName"
151
+ textfield :password_field, "password"
152
+ button :login_button, "//input[@id='submit_button']"
153
+ checkbox :remember_checkbox, "rememberUser']"
154
+ label :error_message_label, 'div#statusBar.login-error'
155
155
 
156
156
  def login(user_id, password)
157
157
  user_id_field.set(user_id)
@@ -198,7 +198,7 @@ specifies the CSS or Xpath expression that uniquely identifies that root node ob
198
198
  You define your page section's **Traits** as shown below:
199
199
 
200
200
  class SearchForm < TestCentricity::PageSection
201
- trait(:section_locator) { "//form[@id='gnav-search']" }
201
+ trait(:section_locator) { "//form[@id='gnav-search']" }
202
202
  end
203
203
 
204
204
 
@@ -207,11 +207,11 @@ You define your page section's **Traits** as shown below:
207
207
  **UI Elements** are added to your **PageSection** class definition as shown below:
208
208
 
209
209
  class SearchForm < TestCentricity::PageSection
210
- trait(:section_locator) { "//form[@id='gnav-search']" }
210
+ trait(:section_locator) { "//form[@id='gnav-search']" }
211
211
 
212
212
  # Search Form UI elements
213
- textfield :search_field, "//input[@id='search-query']"
214
- button :search_button, "//button[@type='submit']"
213
+ textfield :search_field, "//input[@id='search-query']"
214
+ button :search_button, "//button[@type='submit']"
215
215
  end
216
216
 
217
217
 
@@ -220,11 +220,11 @@ You define your page section's **Traits** as shown below:
220
220
  You can add high level methods to your **PageSection** class definition, as shown below:
221
221
 
222
222
  class SearchForm < TestCentricity::PageSection
223
- trait(:section_locator) { "//form[@id='gnav-search']" }
223
+ trait(:section_locator) { "//form[@id='gnav-search']" }
224
224
 
225
225
  # Search Form UI elements
226
- textfield :search_field, "//input[@id='search-query']"
227
- button :search_button, "//button[@type='submit']"
226
+ textfield :search_field, "//input[@id='search-query']"
227
+ button :search_button, "//button[@type='submit']"
228
228
 
229
229
  def search_for(value)
230
230
  search_field.set(value)
@@ -290,17 +290,17 @@ to be instantiated by **PageManager**:
290
290
 
291
291
  module WorldPages
292
292
  def page_objects
293
- { :login_page => LoginPage,
294
- :home_page => HomePage,
295
- :registration_page => RegistrationPage,
296
- :products_grid_page => ProductsCollectionPage,
297
- :product_detail_page => ProductDetailPage,
298
- :shopping_basket_page => ShoppingBasketPage,
299
- :payment_method_page => PaymentMethodPage,
300
- :confirm_purchase_page => PurchaseConfirmationPage,
301
- :my_account_page => MyAccountPage,
302
- :my_order_history_page => MyOrderHistoryPage,
303
- :my_ship_to_addresses_page => MyShipToAddressesPage
293
+ { :login_page => LoginPage,
294
+ :home_page => HomePage,
295
+ :registration_page => RegistrationPage,
296
+ :products_grid_page => ProductsCollectionPage,
297
+ :product_detail_page => ProductDetailPage,
298
+ :shopping_basket_page => ShoppingBasketPage,
299
+ :payment_method_page => PaymentMethodPage,
300
+ :confirm_purchase_page => PurchaseConfirmationPage,
301
+ :my_account_page => MyAccountPage,
302
+ :my_order_history_page => MyOrderHistoryPage,
303
+ :my_ship_to_addresses_page => MyShipToAddressesPage
304
304
  }
305
305
  end
306
306
  end
@@ -1,6 +1,7 @@
1
1
  require 'capybara/cucumber'
2
2
  require 'test/unit'
3
3
  require 'capybara/poltergeist'
4
+
4
5
  require 'testcentricity_web/world_extensions'
5
6
  require 'testcentricity_web/browser_helper'
6
7
  require 'testcentricity_web/data_objects_helper'
@@ -0,0 +1,11 @@
1
+ module TestCentricity
2
+ class Button < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :button
8
+ @alt_locator = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ module TestCentricity
2
+ class CheckBox < UIElement
3
+
4
+ def initialize(parent, locator, context)
5
+ @parent = parent
6
+ @locator = locator
7
+ @context = context
8
+ @type = :checkbox
9
+ @alt_locator = nil
10
+ end
11
+
12
+ # Is checkbox checked?
13
+ #
14
+ # @return [Boolean]
15
+ # @example
16
+ # remember_me_checkbox.checked?
17
+ #
18
+ def checked?
19
+ obj, _ = find_element
20
+ object_not_found_exception(obj, 'Checkbox')
21
+ obj.checked?
22
+ end
23
+
24
+ # Set the check state of a checkbox object.
25
+ #
26
+ # @param state [Boolean] true = checked / false = unchecked
27
+ # @example
28
+ # remember_me_checkbox.set_checkbox_state(true)
29
+ #
30
+ def set_checkbox_state(state)
31
+ obj, _ = find_element
32
+ object_not_found_exception(obj, 'Checkbox')
33
+ invalid_object_type_exception(obj, 'checkbox')
34
+ obj.set(state)
35
+ end
36
+
37
+ def verify_check_state(state, enqueue = false)
38
+ actual = checked?
39
+ enqueue ?
40
+ ExceptionQueue.enqueue_assert_equal(state, actual, "Expected #{@locator}") :
41
+ assert_equal(state, actual, "Expected #{@locator} to be #{state} but found #{actual} instead")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ module TestCentricity
2
+ class FileField < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :filefield
8
+ @alt_locator = nil
9
+ end
10
+
11
+ def attach_file(file_path)
12
+ Capybara.ignore_hidden_elements = false
13
+ page.attach_file(@locator, file_path)
14
+ Capybara.ignore_hidden_elements = true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module TestCentricity
2
+ class Image < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :image
8
+ @alt_locator = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module TestCentricity
2
+ class Label < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :label
8
+ @alt_locator = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module TestCentricity
2
+ class Link < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :link
8
+ @alt_locator = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,82 @@
1
+ module TestCentricity
2
+ class SelectList < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :selectlist
8
+ @alt_locator = nil
9
+ end
10
+
11
+ # Select the specified option in a select box object.
12
+ # Supports standard HTML select objects and Chosen select objects.
13
+ #
14
+ # @param option [String] text of option to select
15
+ # @example
16
+ # province_select.choose_option('Nova Scotia')
17
+ #
18
+ def choose_option(option)
19
+ obj, _ = find_element
20
+ object_not_found_exception(obj, nil)
21
+ obj.click
22
+ if first(:css, 'li.active-result')
23
+ if option.is_a?(Array)
24
+ option.each do |item|
25
+ page.find(:css, 'li.active-result', text: item.strip).click
26
+ end
27
+ else
28
+ first(:css, 'li.active-result', text: option).click
29
+ end
30
+ else
31
+ if option.is_a?(Array)
32
+ option.each do |item|
33
+ obj.select item
34
+ end
35
+ else
36
+ obj.select option
37
+ end
38
+ end
39
+ end
40
+
41
+ # Return array of strings of all options in a select box object.
42
+ # Supports standard HTML select objects and Chosen select objects.
43
+ #
44
+ # @return [Array]
45
+ # @example
46
+ # all_colors = color_select.get_options
47
+ #
48
+ def get_options
49
+ obj, _ = find_element
50
+ object_not_found_exception(obj, nil)
51
+ if first(:css, 'li.active-result')
52
+ obj.all('li.active-result').collect(&:text)
53
+ else
54
+ obj.all('option').collect(&:text)
55
+ end
56
+ end
57
+
58
+ def verify_options(expected, enqueue = false)
59
+ actual = get_options
60
+ enqueue ?
61
+ ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{@locator}") :
62
+ assert_equal(expected, actual, "Expected list of options in list #{@locator} to be #{expected} but found #{actual}")
63
+ end
64
+
65
+ # Return text of first selected option in a select box object.
66
+ # Supports standard HTML select objects and Chosen select objects.
67
+ #
68
+ # @return [String]
69
+ # @example
70
+ # current_color = color_select.get_selected_option
71
+ #
72
+ def get_selected_option
73
+ obj, _ = find_element
74
+ object_not_found_exception(obj, nil)
75
+ if first(:css, 'li.active-result')
76
+ obj.first("//li[contains(@class, 'result-selected')]").text
77
+ else
78
+ obj.first('option[selected]').text
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,264 @@
1
+ module TestCentricity
2
+ class Table < UIElement
3
+ def initialize(parent, locator, context)
4
+ @parent = parent
5
+ @locator = locator
6
+ @context = context
7
+ @type = :table
8
+ @alt_locator = nil
9
+ end
10
+
11
+ # Return number of rows in a table object.
12
+ #
13
+ # @return [Integer]
14
+ # @example
15
+ # num_rows = list_table.get_row_count
16
+ #
17
+ def get_row_count
18
+ wait_until_exists(5)
19
+ row_count = page.all(:xpath, "#{@locator}/tbody/tr", :visible => :all).count
20
+ row_count
21
+ end
22
+
23
+ # Return number of columns in a table object.
24
+ #
25
+ # @return [Integer]
26
+ # @example
27
+ # num_columns = list_table.get_column_count
28
+ #
29
+ def get_column_count
30
+ row_count = get_row_count
31
+ if row_count == 0
32
+ page.all(:xpath, "#{@locator}/thead/tr/th", :visible => :all).count
33
+ else
34
+ (row_count == 1) ?
35
+ page.all(:xpath, "#{@locator}/tbody/tr/td", :visible => :all).count :
36
+ page.all(:xpath, "#{@locator}/tbody/tr[2]/td", :visible => :all).count
37
+ end
38
+ end
39
+
40
+ # Click in the specified cell in a table object.
41
+ #
42
+ # @param row [Integer] row number
43
+ # @param column [Integer] column number
44
+ # @example
45
+ # list_table.click_table_cell(3, 5)
46
+ #
47
+ def click_table_cell(row, column)
48
+ row_count = get_row_count
49
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
50
+ column_count = get_column_count
51
+ raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
52
+ set_table_cell_locator(row, column)
53
+ click
54
+ clear_alt_locator
55
+ end
56
+
57
+ # Double-click in the specified cell in a table object.
58
+ #
59
+ # @param row [Integer] row number
60
+ # @param column [Integer] column number
61
+ # @example
62
+ # list_table.double_click_table_cell(3, 5)
63
+ #
64
+ def double_click_table_cell(row, column)
65
+ row_count = get_row_count
66
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
67
+ column_count = get_column_count
68
+ raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
69
+ set_table_cell_locator(row, column)
70
+ double_click
71
+ clear_alt_locator
72
+ end
73
+
74
+ # Click the link object embedded within the specified cell in a table object.
75
+ #
76
+ # @param row [Integer] row number
77
+ # @param column [Integer] column number
78
+ # @example
79
+ # list_table.click_table_cell_link(3, 1)
80
+ #
81
+ def click_table_cell_link(row, column)
82
+ row_count = get_row_count
83
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
84
+ column_count = get_column_count
85
+ raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
86
+ set_table_cell_locator(row, column)
87
+ saved_locator = @alt_locator
88
+ set_alt_locator("#{@alt_locator}/a")
89
+ set_alt_locator("#{saved_locator}/span/a") unless exists?
90
+ # if link not present, check for text entry fields and try to dismiss by tabbing out
91
+ unless exists?
92
+ set_alt_locator("#{saved_locator}/input")
93
+ set_alt_locator("#{saved_locator}/textarea") unless exists?
94
+ send_keys(:tab) if exists?
95
+ set_alt_locator("#{saved_locator}/a")
96
+ set_alt_locator("#{saved_locator}/span/a") unless exists?
97
+ send_keys(:tab) unless exists?
98
+ end
99
+ wait_until_exists(1)
100
+ click
101
+ clear_alt_locator
102
+ end
103
+
104
+ def get_table_row(row)
105
+ columns = []
106
+ row_count = get_row_count
107
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
108
+ column_count = get_column_count
109
+ (1..column_count).each do |column|
110
+ value = ''
111
+ set_table_cell_locator(row, column)
112
+ saved_locator = @alt_locator
113
+ set_alt_locator("#{saved_locator}/input")
114
+ unless exists?
115
+ set_alt_locator("#{saved_locator}/textarea")
116
+ unless exists?
117
+ set_alt_locator(saved_locator)
118
+ end
119
+ end
120
+ value = get_value if exists?
121
+ columns.push(value)
122
+ end
123
+ clear_alt_locator
124
+ columns
125
+ end
126
+
127
+ def get_row_data(row)
128
+ row_count = get_row_count
129
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
130
+ (row > 1) ?
131
+ set_alt_locator("#{@locator}/tbody/tr[#{row}]") :
132
+ set_alt_locator("#{@locator}/tbody/tr")
133
+ value = get_value if exists?
134
+ clear_alt_locator
135
+ value
136
+ end
137
+
138
+ # Return text contained in specified cell of a table object.
139
+ #
140
+ # @param row [Integer] row number
141
+ # @param column [Integer] column number
142
+ # @return [String] value of table cell
143
+ # @example
144
+ # list_table.get_table_cell(4, 5)
145
+ #
146
+ def get_table_cell(row, column)
147
+ row_count = get_row_count
148
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
149
+ column_count = get_column_count
150
+ raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
151
+ set_table_cell_locator(row, column)
152
+ saved_locator = @alt_locator
153
+ set_alt_locator("#{saved_locator}/input")
154
+ unless exists?
155
+ set_alt_locator("#{saved_locator}/textarea")
156
+ unless exists?
157
+ set_alt_locator(saved_locator)
158
+ end
159
+ end
160
+ value = get_value if exists?
161
+ clear_alt_locator
162
+ value
163
+ end
164
+
165
+ def verify_table_cell(row, column, expected, enqueue = false)
166
+ actual = get_table_cell(row, column)
167
+ enqueue ?
168
+ ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected #{@locator} row #{row}/column #{column}") :
169
+ assert_equal(expected.strip, actual.strip, "Expected #{@locator} row #{row}/column #{column} to display '#{expected}' but found '#{actual}'")
170
+ end
171
+
172
+ # Set the value of the specified cell in a table object.
173
+ #
174
+ # @param row [Integer] row number
175
+ # @param column [Integer] column number
176
+ # @param value [String] text to set
177
+ # @example
178
+ # list_table.set_table_cell(3, 1, 'Ontario')
179
+ #
180
+ def set_table_cell(row, column, value)
181
+ row_count = get_row_count
182
+ raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
183
+ # column_count = get_column_count
184
+ # raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
185
+ set_table_cell_locator(row, column)
186
+ click if exists?
187
+ saved_locator = @alt_locator
188
+ set_alt_locator("#{saved_locator}/input")
189
+ set_alt_locator("#{saved_locator}/textarea") unless exists?
190
+ set(value)
191
+ clear_alt_locator
192
+ end
193
+
194
+ def find_in_table_row(row, search_value)
195
+ (1..get_column_count).each do |column|
196
+ return column if get_table_cell(row, column) == search_value
197
+ end
198
+ nil
199
+ end
200
+
201
+ def find_in_table_column(column, search_value)
202
+ (1..get_row_count).each do |row|
203
+ return row if get_table_cell(row, column) == search_value
204
+ end
205
+ nil
206
+ end
207
+
208
+ def populate_table_row(row, data)
209
+ wait_until_exists(2)
210
+ data.each do | column, data_param |
211
+ unless data_param.blank?
212
+ if data_param == '!DELETE'
213
+ set_table_cell(row, column, '')
214
+ else
215
+ set_table_cell(row, column, data_param)
216
+ end
217
+ end
218
+ end
219
+ end
220
+
221
+ def click_header_column(column)
222
+ column_count = get_column_count
223
+ raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{@locator}" if column > column_count
224
+ (column > 1) ?
225
+ set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
226
+ set_alt_locator("#{@locator}/thead/tr/th")
227
+ click
228
+ clear_alt_locator
229
+ end
230
+
231
+ def get_header_column(column)
232
+ column_count = get_column_count
233
+ raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{@locator}" if column > column_count
234
+ (column > 1) ?
235
+ set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
236
+ set_alt_locator("#{@locator}/thead/tr/th")
237
+ value = get_value
238
+ clear_alt_locator
239
+ value
240
+ end
241
+
242
+ def get_header_columns
243
+ columns = []
244
+ column_count = get_column_count
245
+ (1..column_count).each do |column|
246
+ (column > 1) ?
247
+ set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
248
+ set_alt_locator("#{@locator}/thead/tr/th")
249
+ columns.push(get_value)
250
+ end
251
+ clear_alt_locator
252
+ columns
253
+ end
254
+
255
+ private
256
+
257
+ def set_table_cell_locator(row, column)
258
+ row_spec = "#{@locator}/tbody/tr"
259
+ row_spec = "#{row_spec}[#{row}]" if row > 1
260
+ column_spec = "/td[#{column}]"
261
+ set_alt_locator("#{row_spec}#{column_spec}")
262
+ end
263
+ end
264
+ end