testcentricity_web 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/testcentricity_web/browser_helper.rb +1 -1
- data/lib/testcentricity_web/page_objects_helper.rb +33 -0
- data/lib/testcentricity_web/page_sections_helper.rb +62 -0
- data/lib/testcentricity_web/ui_elements_helper.rb +126 -0
- data/lib/testcentricity_web/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a7fa37b1e2a170c3dfe53463b2f32c345c6bc8
|
4
|
+
data.tar.gz: 12b13c153ae52006acef1010136cb532aff35bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 171dd73728c60562a7ce1895c2e9a18631440c7cdb6d7c375d95621c674d129870d63836213506db407eada9cc8a3249bc6863078e1f0cb80f59999d2b4be9b2
|
7
|
+
data.tar.gz: 3059f83f6a3258232ea6aa41ae89cd7a76ddb6780cc0a427f185e9cd4d7f9a6b15e66a8bd4d968a64efad5424dcc8043b4830ab73743b1168d39a11bdb37bf83
|
@@ -7,6 +7,15 @@ module TestCentricity
|
|
7
7
|
include RSpec::Matchers
|
8
8
|
include Test::Unit::Assertions
|
9
9
|
|
10
|
+
# Define a trait for this page object.
|
11
|
+
#
|
12
|
+
# @param trait_name [symbol] name of trait
|
13
|
+
# @param block [&block] trait value
|
14
|
+
# @example
|
15
|
+
# trait(:page_name) { 'Shopping Basket' }
|
16
|
+
# trait(:page_url) { "/shopping_basket" }
|
17
|
+
# trait(:page_locator) { "//body[@class='shopping_baskets']" }
|
18
|
+
#
|
10
19
|
def self.trait(trait_name, &block)
|
11
20
|
define_method(trait_name.to_s, &block)
|
12
21
|
end
|
@@ -15,14 +24,38 @@ module TestCentricity
|
|
15
24
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :page, nil);end))
|
16
25
|
end
|
17
26
|
|
27
|
+
# Define and instantiate a button UI Element for this page object.
|
28
|
+
#
|
29
|
+
# @param element_name [symbol] name of button object
|
30
|
+
# @param locator [String] css selector or xpath expression that uniquely identifies object
|
31
|
+
# @example
|
32
|
+
# button :checkout_button, "button.checkout_button"
|
33
|
+
# button :login_button, "//input[@id='submit_button']"
|
34
|
+
#
|
18
35
|
def self.button(element_name, locator)
|
19
36
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :page, :button);end))
|
20
37
|
end
|
21
38
|
|
39
|
+
# Define and instantiate a text field UI Element for this page object.
|
40
|
+
#
|
41
|
+
# @param element_name [symbol] name of text field object
|
42
|
+
# @param locator [String] css selector or xpath expression that uniquely identifies object
|
43
|
+
# @example
|
44
|
+
# textfield :user_id_field, "//input[@id='UserName']"
|
45
|
+
# textfield :password_field, "consumer_password"
|
46
|
+
#
|
22
47
|
def self.textfield(element_name, locator)
|
23
48
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :page, :textfield);end))
|
24
49
|
end
|
25
50
|
|
51
|
+
# Define and instantiate a checkbox UI Element for this page object.
|
52
|
+
#
|
53
|
+
# @param element_name [symbol] name of checkbox object
|
54
|
+
# @param locator [String] css selector or xpath expression that uniquely identifies object
|
55
|
+
# @example
|
56
|
+
# checkbox :remember_checkbox, "//input[@id='RememberUser']"
|
57
|
+
# checkbox :accept_terms_checkbox, "accept_terms_conditions"
|
58
|
+
#
|
26
59
|
def self.checkbox(element_name, locator)
|
27
60
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :page, :checkbox);end))
|
28
61
|
end
|
@@ -16,6 +16,14 @@ module TestCentricity
|
|
16
16
|
@context = context
|
17
17
|
end
|
18
18
|
|
19
|
+
# Define a trait for this page section.
|
20
|
+
#
|
21
|
+
# @param trait_name [symbol] name of trait
|
22
|
+
# @param block [&block] trait value
|
23
|
+
# @example
|
24
|
+
# trait(:section_locator) { "//div[@class='Messaging_Applet']" }
|
25
|
+
# trait(:list_table_name) { 'Messages' }
|
26
|
+
#
|
19
27
|
def self.trait(trait_name, &block)
|
20
28
|
define_method(trait_name.to_s, &block)
|
21
29
|
end
|
@@ -24,14 +32,38 @@ module TestCentricity
|
|
24
32
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :section, nil);end))
|
25
33
|
end
|
26
34
|
|
35
|
+
# Define and instantiate a button UI Element for this page section.
|
36
|
+
#
|
37
|
+
# @param element_name [symbol] name of button object
|
38
|
+
# @param locator [String] css selector or xpath expression that uniquely identifies object
|
39
|
+
# @example
|
40
|
+
# button :checkout_button, "button.checkout_button"
|
41
|
+
# button :login_button, "//input[@id='submit_button']"
|
42
|
+
#
|
27
43
|
def self.button(element_name, locator)
|
28
44
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :section, :button);end))
|
29
45
|
end
|
30
46
|
|
47
|
+
# Define and instantiate a text field UI Element for this page section.
|
48
|
+
#
|
49
|
+
# @param element_name [symbol] name of text field object
|
50
|
+
# @param locator [String] css selector or xpath expression that uniquely identifies object
|
51
|
+
# @example
|
52
|
+
# textfield :user_id_field, "//input[@id='UserName']"
|
53
|
+
# textfield :password_field, "consumer_password"
|
54
|
+
#
|
31
55
|
def self.textfield(element_name, locator)
|
32
56
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :section, :textfield);end))
|
33
57
|
end
|
34
58
|
|
59
|
+
# Define and instantiate a checkbox UI Element for this page section.
|
60
|
+
#
|
61
|
+
# @param element_name [symbol] name of checkbox object
|
62
|
+
# @param locator [String] css selector or xpath expression that uniquely identifies object
|
63
|
+
# @example
|
64
|
+
# checkbox :remember_checkbox, "//input[@id='RememberUser']"
|
65
|
+
# checkbox :accept_terms_checkbox, "accept_terms_conditions"
|
66
|
+
#
|
35
67
|
def self.checkbox(element_name, locator)
|
36
68
|
class_eval(%Q(def #{element_name.to_s};@#{element_name.to_s} ||= TestCentricity::UIElement.new(self, "#{locator}", :section, :checkbox);end))
|
37
69
|
end
|
@@ -69,11 +101,23 @@ module TestCentricity
|
|
69
101
|
@parent = parent
|
70
102
|
end
|
71
103
|
|
104
|
+
# Does Section object exists?
|
105
|
+
#
|
106
|
+
# @return [Boolean]
|
107
|
+
# @example
|
108
|
+
# navigation_toolbar.exists?
|
109
|
+
#
|
72
110
|
def exists?
|
73
111
|
section, _ = find_section
|
74
112
|
section != nil
|
75
113
|
end
|
76
114
|
|
115
|
+
# Is Section object visible?
|
116
|
+
#
|
117
|
+
# @return [Boolean]
|
118
|
+
# @example
|
119
|
+
# navigation_toolbar.visible?
|
120
|
+
#
|
77
121
|
def visible?
|
78
122
|
section, type = find_section
|
79
123
|
exists = section
|
@@ -94,10 +138,22 @@ module TestCentricity
|
|
94
138
|
(exists && !invisible) ? true : false
|
95
139
|
end
|
96
140
|
|
141
|
+
# Is Section object hidden (not visible)?
|
142
|
+
#
|
143
|
+
# @return [Boolean]
|
144
|
+
# @example
|
145
|
+
# navigation_toolbar.hidden?
|
146
|
+
#
|
97
147
|
def hidden?
|
98
148
|
not visible?
|
99
149
|
end
|
100
150
|
|
151
|
+
# Wait until the Section object exists, or until the specified wait time has expired.
|
152
|
+
#
|
153
|
+
# @param seconds [Integer, Float] wait time in seconds
|
154
|
+
# @example
|
155
|
+
# navigation_toolbar.wait_until_exists(0.5)
|
156
|
+
#
|
101
157
|
def wait_until_exists(seconds)
|
102
158
|
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
103
159
|
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
@@ -106,6 +162,12 @@ module TestCentricity
|
|
106
162
|
raise "Could not find section #{get_locator} after #{timeout} seconds" unless exists?
|
107
163
|
end
|
108
164
|
|
165
|
+
# Wait until the Section object no longer exists, or until the specified wait time has expired.
|
166
|
+
#
|
167
|
+
# @param seconds [Integer, Float] wait time in seconds
|
168
|
+
# @example
|
169
|
+
# navigation_toolbar.wait_until_gone(5)
|
170
|
+
#
|
109
171
|
def wait_until_gone(seconds)
|
110
172
|
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
111
173
|
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
@@ -45,6 +45,11 @@ module TestCentricity
|
|
45
45
|
@alt_locator = nil
|
46
46
|
end
|
47
47
|
|
48
|
+
# Click on an object
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# basket_link.click
|
52
|
+
#
|
48
53
|
def click
|
49
54
|
obj, _ = find_element
|
50
55
|
object_not_found_exception(obj, nil)
|
@@ -55,6 +60,11 @@ module TestCentricity
|
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
63
|
+
# Double-click on an object
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# file_image.double_click
|
67
|
+
#
|
58
68
|
def double_click
|
59
69
|
obj, _ = find_element
|
60
70
|
object_not_found_exception(obj, nil)
|
@@ -73,17 +83,35 @@ module TestCentricity
|
|
73
83
|
obj.set(value)
|
74
84
|
end
|
75
85
|
|
86
|
+
# Send keystrokes to this object.
|
87
|
+
#
|
88
|
+
# @param keys [String] keys
|
89
|
+
# @example
|
90
|
+
# comment_field.send_keys(:enter)
|
91
|
+
#
|
76
92
|
def send_keys(*keys)
|
77
93
|
obj, _ = find_element
|
78
94
|
object_not_found_exception(obj, nil)
|
79
95
|
obj.send_keys(*keys)
|
80
96
|
end
|
81
97
|
|
98
|
+
# Does UI object exists?
|
99
|
+
#
|
100
|
+
# @return [Boolean]
|
101
|
+
# @example
|
102
|
+
# basket_link.exists?
|
103
|
+
#
|
82
104
|
def exists?
|
83
105
|
obj, _ = find_element
|
84
106
|
obj != nil
|
85
107
|
end
|
86
108
|
|
109
|
+
# Is UI object visible?
|
110
|
+
#
|
111
|
+
# @return [Boolean]
|
112
|
+
# @example
|
113
|
+
# remember_me_checkbox.visible?
|
114
|
+
#
|
87
115
|
def visible?
|
88
116
|
obj, type = find_element
|
89
117
|
exists = obj
|
@@ -106,32 +134,68 @@ module TestCentricity
|
|
106
134
|
(exists && !invisible) ? true : false
|
107
135
|
end
|
108
136
|
|
137
|
+
# Is UI object hidden (not visible)?
|
138
|
+
#
|
139
|
+
# @return [Boolean]
|
140
|
+
# @example
|
141
|
+
# remember_me_checkbox.hidden?
|
142
|
+
#
|
109
143
|
def hidden?
|
110
144
|
not visible?
|
111
145
|
end
|
112
146
|
|
147
|
+
# Is UI object enabled?
|
148
|
+
#
|
149
|
+
# @return [Boolean]
|
150
|
+
# @example
|
151
|
+
# login_button.enabled?
|
152
|
+
#
|
113
153
|
def enabled?
|
114
154
|
not disabled?
|
115
155
|
end
|
116
156
|
|
157
|
+
# Is UI object disabled (not enabled)?
|
158
|
+
#
|
159
|
+
# @return [Boolean]
|
160
|
+
# @example
|
161
|
+
# login_button.disabled?
|
162
|
+
#
|
117
163
|
def disabled?
|
118
164
|
obj, _ = find_element
|
119
165
|
object_not_found_exception(obj, nil)
|
120
166
|
obj.disabled?
|
121
167
|
end
|
122
168
|
|
169
|
+
# Is text field set to read-only?
|
170
|
+
#
|
171
|
+
# @return [Boolean]
|
172
|
+
# @example
|
173
|
+
# comments_field.read_only?
|
174
|
+
#
|
123
175
|
def read_only?
|
124
176
|
obj, _ = find_element
|
125
177
|
object_not_found_exception(obj, nil)
|
126
178
|
!!obj.native.attribute('readonly')
|
127
179
|
end
|
128
180
|
|
181
|
+
# Return maxlength character count of a text field.
|
182
|
+
#
|
183
|
+
# @return [Integer]
|
184
|
+
# @example
|
185
|
+
# max_num_chars = comments_field.get_max_length
|
186
|
+
#
|
129
187
|
def get_max_length
|
130
188
|
obj, _ = find_element
|
131
189
|
object_not_found_exception(obj, nil)
|
132
190
|
obj.native.attribute('maxlength')
|
133
191
|
end
|
134
192
|
|
193
|
+
# Is checkbox checked?
|
194
|
+
#
|
195
|
+
# @return [Boolean]
|
196
|
+
# @example
|
197
|
+
# remember_me_checkbox.checked?
|
198
|
+
#
|
135
199
|
def checked?
|
136
200
|
obj, _ = find_element
|
137
201
|
object_not_found_exception(obj, 'Checkbox')
|
@@ -152,6 +216,12 @@ module TestCentricity
|
|
152
216
|
assert_equal(state, actual, "Expected #{@locator} to be #{state} but found #{actual} instead")
|
153
217
|
end
|
154
218
|
|
219
|
+
# Wait until the object exists, or until the specified wait time has expired.
|
220
|
+
#
|
221
|
+
# @param seconds [Integer, Float] wait time in seconds
|
222
|
+
# @example
|
223
|
+
# run_button.wait_until_exists(0.5)
|
224
|
+
#
|
155
225
|
def wait_until_exists(seconds)
|
156
226
|
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
157
227
|
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
@@ -160,6 +230,12 @@ module TestCentricity
|
|
160
230
|
raise "Could not find element #{@locator} after #{timeout} seconds" unless exists?
|
161
231
|
end
|
162
232
|
|
233
|
+
# Wait until the object no longer exists, or until the specified wait time has expired.
|
234
|
+
#
|
235
|
+
# @param seconds [Integer, Float] wait time in seconds
|
236
|
+
# @example
|
237
|
+
# logout_button.wait_until_gone(5)
|
238
|
+
#
|
163
239
|
def wait_until_gone(seconds)
|
164
240
|
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
165
241
|
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
@@ -168,6 +244,12 @@ module TestCentricity
|
|
168
244
|
raise "Element #{@locator} remained visible after #{timeout} seconds" if exists?
|
169
245
|
end
|
170
246
|
|
247
|
+
# Wait until the object's value equals the specified value, or until the specified wait time has expired.
|
248
|
+
#
|
249
|
+
# @param seconds [Integer, Float] wait time in seconds
|
250
|
+
# @example
|
251
|
+
# card_authorized_label.wait_until_value_is(5, 'Card authorized')
|
252
|
+
#
|
171
253
|
def wait_until_value_is(value, seconds)
|
172
254
|
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
173
255
|
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
@@ -176,6 +258,12 @@ module TestCentricity
|
|
176
258
|
raise "Value of UI element #{@locator} failed to equal '#{value}' after #{timeout} seconds" unless exists?
|
177
259
|
end
|
178
260
|
|
261
|
+
# Wait until the object's value changes to a different value, or until the specified wait time has expired.
|
262
|
+
#
|
263
|
+
# @param seconds [Integer, Float] wait time in seconds
|
264
|
+
# @example
|
265
|
+
# basket_grand_total_label.wait_until_value_changes(5)
|
266
|
+
#
|
179
267
|
def wait_until_value_changes(seconds)
|
180
268
|
value = get_value
|
181
269
|
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
@@ -203,6 +291,11 @@ module TestCentricity
|
|
203
291
|
assert_equal(expected.strip, actual.strip, "Expected #{@locator} to display '#{expected}' but found '#{actual}'")
|
204
292
|
end
|
205
293
|
|
294
|
+
# Hover the cursor over an object
|
295
|
+
#
|
296
|
+
# @example
|
297
|
+
# basket_link.hover
|
298
|
+
#
|
206
299
|
def hover
|
207
300
|
obj, _ = find_element
|
208
301
|
object_not_found_exception(obj, nil)
|
@@ -256,12 +349,24 @@ module TestCentricity
|
|
256
349
|
obj.first('option[selected]').text
|
257
350
|
end
|
258
351
|
|
352
|
+
# Return number of rows in a table object.
|
353
|
+
#
|
354
|
+
# @return [Integer]
|
355
|
+
# @example
|
356
|
+
# num_rows = list_table.get_row_count
|
357
|
+
#
|
259
358
|
def get_row_count
|
260
359
|
wait_until_exists(5)
|
261
360
|
row_count = page.all(:xpath, "#{@locator}/tbody/tr", :visible => :all).count
|
262
361
|
row_count
|
263
362
|
end
|
264
363
|
|
364
|
+
# Return number of columns in a table object.
|
365
|
+
#
|
366
|
+
# @return [Integer]
|
367
|
+
# @example
|
368
|
+
# num_columns = list_table.get_column_count
|
369
|
+
#
|
265
370
|
def get_column_count
|
266
371
|
row_count = get_row_count
|
267
372
|
if row_count == 0
|
@@ -273,6 +378,13 @@ module TestCentricity
|
|
273
378
|
end
|
274
379
|
end
|
275
380
|
|
381
|
+
# Click in the specified cell in a table object.
|
382
|
+
#
|
383
|
+
# @param row [Integer] row number
|
384
|
+
# @param column [Integer] column number
|
385
|
+
# @example
|
386
|
+
# list_table.click_table_cell(3, 5)
|
387
|
+
#
|
276
388
|
def click_table_cell(row, column)
|
277
389
|
row_count = get_row_count
|
278
390
|
raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
|
@@ -283,6 +395,13 @@ module TestCentricity
|
|
283
395
|
clear_alt_locator
|
284
396
|
end
|
285
397
|
|
398
|
+
# Double-click in the specified cell in a table object.
|
399
|
+
#
|
400
|
+
# @param row [Integer] row number
|
401
|
+
# @param column [Integer] column number
|
402
|
+
# @example
|
403
|
+
# list_table.double_click_table_cell(3, 5)
|
404
|
+
#
|
286
405
|
def double_click_table_cell(row, column)
|
287
406
|
row_count = get_row_count
|
288
407
|
raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
|
@@ -293,6 +412,13 @@ module TestCentricity
|
|
293
412
|
clear_alt_locator
|
294
413
|
end
|
295
414
|
|
415
|
+
# Click the link object embedded within the specified cell in a table object.
|
416
|
+
#
|
417
|
+
# @param row [Integer] row number
|
418
|
+
# @param column [Integer] column number
|
419
|
+
# @example
|
420
|
+
# list_table.click_table_cell_link(3, 1)
|
421
|
+
#
|
296
422
|
def click_table_cell_link(row, column)
|
297
423
|
row_count = get_row_count
|
298
424
|
raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
|