testcentricity 2.3.13
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +93 -0
- data/LICENSE.txt +28 -0
- data/README.md +1634 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/devices/devices.yml +344 -0
- data/lib/testcentricity.rb +144 -0
- data/lib/testcentricity/app_core/appium_connect_helper.rb +154 -0
- data/lib/testcentricity/app_core/appium_server.rb +69 -0
- data/lib/testcentricity/app_core/screen_objects_helper.rb +180 -0
- data/lib/testcentricity/app_core/screen_sections_helper.rb +332 -0
- data/lib/testcentricity/app_elements/app_element_helper.rb +293 -0
- data/lib/testcentricity/app_elements/button.rb +8 -0
- data/lib/testcentricity/app_elements/checkbox.rb +20 -0
- data/lib/testcentricity/app_elements/label.rb +8 -0
- data/lib/testcentricity/app_elements/list.rb +25 -0
- data/lib/testcentricity/app_elements/switch.rb +20 -0
- data/lib/testcentricity/app_elements/textfield.rb +12 -0
- data/lib/testcentricity/browser_helper.rb +174 -0
- data/lib/testcentricity/data_objects/data_objects_helper.rb +78 -0
- data/lib/testcentricity/data_objects/environment.rb +281 -0
- data/lib/testcentricity/data_objects/excel_helper.rb +242 -0
- data/lib/testcentricity/exception_queue_helper.rb +51 -0
- data/lib/testcentricity/utility_helpers.rb +28 -0
- data/lib/testcentricity/version.rb +3 -0
- data/lib/testcentricity/web_core/drag_drop_helper.rb +15 -0
- data/lib/testcentricity/web_core/page_objects_helper.rb +669 -0
- data/lib/testcentricity/web_core/page_sections_helper.rb +866 -0
- data/lib/testcentricity/web_core/webdriver_helper.rb +579 -0
- data/lib/testcentricity/web_elements/button.rb +8 -0
- data/lib/testcentricity/web_elements/cell_button.rb +8 -0
- data/lib/testcentricity/web_elements/cell_checkbox.rb +38 -0
- data/lib/testcentricity/web_elements/cell_element.rb +69 -0
- data/lib/testcentricity/web_elements/cell_image.rb +8 -0
- data/lib/testcentricity/web_elements/cell_radio.rb +31 -0
- data/lib/testcentricity/web_elements/checkbox.rb +100 -0
- data/lib/testcentricity/web_elements/file_field.rb +45 -0
- data/lib/testcentricity/web_elements/image.rb +34 -0
- data/lib/testcentricity/web_elements/label.rb +8 -0
- data/lib/testcentricity/web_elements/link.rb +8 -0
- data/lib/testcentricity/web_elements/list.rb +73 -0
- data/lib/testcentricity/web_elements/list_button.rb +8 -0
- data/lib/testcentricity/web_elements/list_checkbox.rb +38 -0
- data/lib/testcentricity/web_elements/list_element.rb +61 -0
- data/lib/testcentricity/web_elements/list_radio.rb +31 -0
- data/lib/testcentricity/web_elements/radio.rb +74 -0
- data/lib/testcentricity/web_elements/select_list.rb +197 -0
- data/lib/testcentricity/web_elements/siebel_open_ui_helper.rb +15 -0
- data/lib/testcentricity/web_elements/table.rb +612 -0
- data/lib/testcentricity/web_elements/textfield.rb +114 -0
- data/lib/testcentricity/web_elements/ui_elements_helper.rb +502 -0
- data/lib/testcentricity/world_extensions.rb +26 -0
- data/my_templates/default/method_details/setup.rb +3 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/testcentricity_spec.rb +9 -0
- data/testcentricity.gemspec +47 -0
- metadata +328 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
class TextField < UIElement
|
3
|
+
def initialize(name, parent, locator, context)
|
4
|
+
super
|
5
|
+
@type = :textfield
|
6
|
+
end
|
7
|
+
|
8
|
+
# Is text field set to read-only?
|
9
|
+
#
|
10
|
+
# @return [Boolean]
|
11
|
+
# @example
|
12
|
+
# comments_field.read_only?
|
13
|
+
#
|
14
|
+
def read_only?
|
15
|
+
obj, = find_element
|
16
|
+
object_not_found_exception(obj, nil)
|
17
|
+
!!obj.native.attribute('readonly')
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return maxlength character count of a text field.
|
21
|
+
#
|
22
|
+
# @return [Integer]
|
23
|
+
# @example
|
24
|
+
# max_num_chars = comments_field.get_max_length
|
25
|
+
#
|
26
|
+
def get_max_length
|
27
|
+
obj, = find_element
|
28
|
+
object_not_found_exception(obj, nil)
|
29
|
+
max_length = obj.native.attribute('maxlength')
|
30
|
+
max_length.to_i unless max_length.blank?
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return placeholder text of a text field.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
# @example
|
37
|
+
# placeholder_message = username_field.get_placeholder
|
38
|
+
#
|
39
|
+
def get_placeholder
|
40
|
+
obj, = find_element
|
41
|
+
object_not_found_exception(obj, nil)
|
42
|
+
obj.native.attribute('placeholder')
|
43
|
+
end
|
44
|
+
|
45
|
+
# Return min attribute of a number type text field.
|
46
|
+
#
|
47
|
+
# @return [Integer]
|
48
|
+
# @example
|
49
|
+
# min_points_value = points_field.get_min
|
50
|
+
#
|
51
|
+
def get_min
|
52
|
+
obj, = find_element
|
53
|
+
object_not_found_exception(obj, nil)
|
54
|
+
min = obj.native.attribute('min')
|
55
|
+
min.to_i unless min.blank?
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return max attribute of a number type text field.
|
59
|
+
#
|
60
|
+
# @return [Integer]
|
61
|
+
# @example
|
62
|
+
# max_points_value = points_field.get_max
|
63
|
+
#
|
64
|
+
def get_max
|
65
|
+
obj, = find_element
|
66
|
+
object_not_found_exception(obj, nil)
|
67
|
+
max = obj.native.attribute('max')
|
68
|
+
max.to_i unless max.blank?
|
69
|
+
end
|
70
|
+
|
71
|
+
# Return step attribute of a number type text field.
|
72
|
+
#
|
73
|
+
# @return [Integer]
|
74
|
+
# @example
|
75
|
+
# points_step = points_field.get_step
|
76
|
+
#
|
77
|
+
def get_step
|
78
|
+
obj, = find_element
|
79
|
+
object_not_found_exception(obj, nil)
|
80
|
+
step = obj.native.attribute('step')
|
81
|
+
step.to_i unless step.blank?
|
82
|
+
end
|
83
|
+
|
84
|
+
# Clear the contents of a text field
|
85
|
+
#
|
86
|
+
# @example
|
87
|
+
# first_name_field.clear
|
88
|
+
#
|
89
|
+
def clear
|
90
|
+
case get_native_attribute('tagName').downcase.to_sym
|
91
|
+
when :textarea
|
92
|
+
set('')
|
93
|
+
sleep(0.5)
|
94
|
+
send_keys(:tab)
|
95
|
+
when :div
|
96
|
+
set('')
|
97
|
+
else
|
98
|
+
length = get_value.length
|
99
|
+
length.times do
|
100
|
+
send_keys(:backspace)
|
101
|
+
end
|
102
|
+
sleep(0.5)
|
103
|
+
send_keys(:tab)
|
104
|
+
sleep(0.5)
|
105
|
+
length = get_value.length
|
106
|
+
if length > 0
|
107
|
+
set('')
|
108
|
+
sleep(0.5)
|
109
|
+
send_keys(:tab)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,502 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
Capybara::Node::Element.class_eval do
|
4
|
+
def click_at(x, y)
|
5
|
+
right = x - (native.size.width / 2)
|
6
|
+
top = y - (native.size.height / 2)
|
7
|
+
driver.browser.action.move_to(native).move_by(right.to_i, top.to_i).click.perform
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_width
|
11
|
+
native.size.width
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_height
|
15
|
+
native.size.height
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_x
|
19
|
+
native.location.x
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_y
|
23
|
+
native.location.y
|
24
|
+
end
|
25
|
+
|
26
|
+
def displayed?
|
27
|
+
native.displayed?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
module TestCentricity
|
33
|
+
class UIElement
|
34
|
+
include Capybara::DSL
|
35
|
+
include Test::Unit::Assertions
|
36
|
+
|
37
|
+
attr_reader :parent, :locator, :context, :type, :name
|
38
|
+
attr_accessor :alt_locator, :locator_type
|
39
|
+
|
40
|
+
XPATH_SELECTORS = ['//', '[@', '[contains(@']
|
41
|
+
CSS_SELECTORS = ['#', ':nth-child(', ':nth-of-type(', '^=', '$=', '*=']
|
42
|
+
|
43
|
+
def initialize(name, parent, locator, context)
|
44
|
+
@name = name
|
45
|
+
@parent = parent
|
46
|
+
@locator = locator
|
47
|
+
@context = context
|
48
|
+
@type = nil
|
49
|
+
@alt_locator = nil
|
50
|
+
set_locator_type
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_locator_type(locator = nil)
|
54
|
+
locator = @locator if locator.nil?
|
55
|
+
is_xpath = XPATH_SELECTORS.any? { |selector| locator.include?(selector) }
|
56
|
+
is_css = CSS_SELECTORS.any? { |selector| locator.include?(selector) }
|
57
|
+
if is_xpath && !is_css
|
58
|
+
@locator_type = :xpath
|
59
|
+
elsif is_css && !is_xpath
|
60
|
+
@locator_type = :css
|
61
|
+
elsif !is_css && !is_xpath
|
62
|
+
@locator_type = :css
|
63
|
+
else
|
64
|
+
raise "Cannot determine type of locator for UIElement '#{@name}' - locator = #{locator}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_object_type
|
69
|
+
if @type
|
70
|
+
@type
|
71
|
+
elsif obj.tag_name
|
72
|
+
obj.tag_name
|
73
|
+
elsif obj.native.attribute('type')
|
74
|
+
obj.native.attribute('type')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_locator
|
79
|
+
@locator
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_name
|
83
|
+
@name
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_alt_locator(temp_locator)
|
87
|
+
@alt_locator = temp_locator
|
88
|
+
end
|
89
|
+
|
90
|
+
def clear_alt_locator
|
91
|
+
@alt_locator = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
# Click on an object
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# basket_link.click
|
98
|
+
#
|
99
|
+
def click
|
100
|
+
obj, type = find_element
|
101
|
+
object_not_found_exception(obj, type)
|
102
|
+
begin
|
103
|
+
obj.click
|
104
|
+
rescue
|
105
|
+
obj.click_at(10, 10) unless Capybara.current_driver == :poltergeist
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Double-click on an object
|
110
|
+
#
|
111
|
+
# @example
|
112
|
+
# file_image.double_click
|
113
|
+
#
|
114
|
+
def double_click
|
115
|
+
obj, type = find_element
|
116
|
+
object_not_found_exception(obj, type)
|
117
|
+
page.driver.browser.action.double_click(obj.native).perform
|
118
|
+
end
|
119
|
+
|
120
|
+
# Right-click on an object
|
121
|
+
#
|
122
|
+
# @example
|
123
|
+
# basket_item_image.right_click
|
124
|
+
#
|
125
|
+
def right_click
|
126
|
+
obj, type = find_element
|
127
|
+
object_not_found_exception(obj, type)
|
128
|
+
page.driver.browser.action.context_click(obj.native).perform
|
129
|
+
end
|
130
|
+
|
131
|
+
# Click at a specific location within an object
|
132
|
+
#
|
133
|
+
# @param x [Integer] X offset
|
134
|
+
# @param y [Integer] Y offset
|
135
|
+
# @example
|
136
|
+
# basket_item_image.click_at(10, 10)
|
137
|
+
#
|
138
|
+
def click_at(x, y)
|
139
|
+
obj, = find_element
|
140
|
+
raise "UI #{object_ref_message} not found" unless obj
|
141
|
+
obj.click_at(x, y)
|
142
|
+
end
|
143
|
+
|
144
|
+
def set(value)
|
145
|
+
obj, type = find_element
|
146
|
+
object_not_found_exception(obj, type)
|
147
|
+
obj.set(value)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Send keystrokes to this object.
|
151
|
+
#
|
152
|
+
# @param keys [String] keys
|
153
|
+
# @example
|
154
|
+
# comment_field.send_keys(:enter)
|
155
|
+
#
|
156
|
+
def send_keys(*keys)
|
157
|
+
obj, type = find_element
|
158
|
+
object_not_found_exception(obj, type)
|
159
|
+
obj.send_keys(*keys)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Does UI object exists?
|
163
|
+
#
|
164
|
+
# @return [Boolean]
|
165
|
+
# @example
|
166
|
+
# basket_link.exists?
|
167
|
+
#
|
168
|
+
def exists?(visible = true)
|
169
|
+
obj, = find_object(visible)
|
170
|
+
obj != nil
|
171
|
+
end
|
172
|
+
|
173
|
+
# Is UI object visible?
|
174
|
+
#
|
175
|
+
# @return [Boolean]
|
176
|
+
# @example
|
177
|
+
# remember_me_checkbox.visible?
|
178
|
+
#
|
179
|
+
def visible?
|
180
|
+
obj, type = find_object
|
181
|
+
exists = obj
|
182
|
+
invisible = false
|
183
|
+
if type == :css
|
184
|
+
Capybara.using_wait_time 0.1 do
|
185
|
+
# is object itself hidden with .ui-helper-hidden class?
|
186
|
+
self_hidden = page.has_css?("#{@locator}.ui-helper-hidden")
|
187
|
+
# is parent of object hidden, thus hiding the object?
|
188
|
+
parent_hidden = page.has_css?(".ui-helper-hidden > #{@locator}")
|
189
|
+
# is grandparent of object, or any other ancestor, hidden?
|
190
|
+
other_ancestor_hidden = page.has_css?(".ui-helper-hidden * #{@locator}")
|
191
|
+
# if any of the above conditions are true, then object is invisible
|
192
|
+
invisible = self_hidden || parent_hidden || other_ancestor_hidden
|
193
|
+
end
|
194
|
+
else
|
195
|
+
invisible = !obj.visible? if exists
|
196
|
+
end
|
197
|
+
# the object is visible if it exists and it is not invisible
|
198
|
+
if exists && !invisible
|
199
|
+
true
|
200
|
+
else
|
201
|
+
false
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Is UI object hidden (not visible)?
|
206
|
+
#
|
207
|
+
# @return [Boolean]
|
208
|
+
# @example
|
209
|
+
# remember_me_checkbox.hidden?
|
210
|
+
#
|
211
|
+
def hidden?
|
212
|
+
!visible?
|
213
|
+
end
|
214
|
+
|
215
|
+
# Is UI object enabled?
|
216
|
+
#
|
217
|
+
# @return [Boolean]
|
218
|
+
# @example
|
219
|
+
# login_button.enabled?
|
220
|
+
#
|
221
|
+
def enabled?
|
222
|
+
!disabled?
|
223
|
+
end
|
224
|
+
|
225
|
+
# Is UI object disabled (not enabled)?
|
226
|
+
#
|
227
|
+
# @return [Boolean]
|
228
|
+
# @example
|
229
|
+
# login_button.disabled?
|
230
|
+
#
|
231
|
+
def disabled?
|
232
|
+
obj, type = find_element
|
233
|
+
object_not_found_exception(obj, type)
|
234
|
+
obj.disabled?
|
235
|
+
end
|
236
|
+
|
237
|
+
# Wait until the object exists, or until the specified wait time has expired. If the wait time is nil, then the wait
|
238
|
+
# time will be Capybara.default_max_wait_time.
|
239
|
+
#
|
240
|
+
# @param seconds [Integer or Float] wait time in seconds
|
241
|
+
# @example
|
242
|
+
# run_button.wait_until_exists(0.5)
|
243
|
+
#
|
244
|
+
def wait_until_exists(seconds = nil)
|
245
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
246
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
247
|
+
wait.until { exists? }
|
248
|
+
rescue
|
249
|
+
raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless exists?
|
250
|
+
end
|
251
|
+
|
252
|
+
# Wait until the object no longer exists, or until the specified wait time has expired. If the wait time is nil, then
|
253
|
+
# the wait time will be Capybara.default_max_wait_time.
|
254
|
+
#
|
255
|
+
# @param seconds [Integer or Float] wait time in seconds
|
256
|
+
# @example
|
257
|
+
# logout_button.wait_until_gone(5)
|
258
|
+
#
|
259
|
+
def wait_until_gone(seconds = nil)
|
260
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
261
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
262
|
+
wait.until { !exists? }
|
263
|
+
rescue
|
264
|
+
raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if exists?
|
265
|
+
end
|
266
|
+
|
267
|
+
# Wait until the object is visible, or until the specified wait time has expired. If the wait time is nil, then the
|
268
|
+
# wait time will be Capybara.default_max_wait_time.
|
269
|
+
#
|
270
|
+
# @param seconds [Integer or Float] wait time in seconds
|
271
|
+
# @example
|
272
|
+
# run_button.wait_until_visible(0.5)
|
273
|
+
#
|
274
|
+
def wait_until_visible(seconds = nil)
|
275
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
276
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
277
|
+
wait.until { visible? }
|
278
|
+
rescue
|
279
|
+
raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless visible?
|
280
|
+
end
|
281
|
+
|
282
|
+
# Wait until the object is hidden, or until the specified wait time has expired. If the wait time is nil, then the
|
283
|
+
# wait time will be Capybara.default_max_wait_time.
|
284
|
+
#
|
285
|
+
# @param seconds [Integer or Float] wait time in seconds
|
286
|
+
# @example
|
287
|
+
# run_button.wait_until_hidden(10)
|
288
|
+
#
|
289
|
+
def wait_until_hidden(seconds = nil)
|
290
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
291
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
292
|
+
wait.until { hidden? }
|
293
|
+
rescue
|
294
|
+
raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if visible?
|
295
|
+
end
|
296
|
+
|
297
|
+
# Wait until the object's value equals the specified value, or until the specified wait time has expired. If the wait
|
298
|
+
# time is nil, then the wait time will be Capybara.default_max_wait_time.
|
299
|
+
#
|
300
|
+
# @param seconds [Integer or Float] wait time in seconds
|
301
|
+
# @example
|
302
|
+
# card_authorized_label.wait_until_value_is(5, 'Card authorized')
|
303
|
+
#
|
304
|
+
def wait_until_value_is(value, seconds = nil)
|
305
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
306
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
307
|
+
wait.until { get_value == value }
|
308
|
+
rescue
|
309
|
+
raise "Value of UI #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value
|
310
|
+
end
|
311
|
+
|
312
|
+
# Wait until the object's value changes to a different value, or until the specified wait time has expired. If the
|
313
|
+
# wait time is nil, then the wait time will be Capybara.default_max_wait_time.
|
314
|
+
#
|
315
|
+
# @param seconds [Integer or Float] wait time in seconds
|
316
|
+
# @example
|
317
|
+
# basket_grand_total_label.wait_until_value_changes(5)
|
318
|
+
#
|
319
|
+
def wait_until_value_changes(seconds = nil)
|
320
|
+
value = get_value
|
321
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
322
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
323
|
+
wait.until { get_value != value }
|
324
|
+
rescue
|
325
|
+
raise "Value of UI #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_value == value
|
326
|
+
end
|
327
|
+
|
328
|
+
# Return width of object.
|
329
|
+
#
|
330
|
+
# @return [Integer]
|
331
|
+
# @example
|
332
|
+
# button_width = my_button.width
|
333
|
+
#
|
334
|
+
def width
|
335
|
+
obj, type = find_element(false)
|
336
|
+
object_not_found_exception(obj, type)
|
337
|
+
obj.get_width
|
338
|
+
end
|
339
|
+
|
340
|
+
# Return height of object.
|
341
|
+
#
|
342
|
+
# @return [Integer]
|
343
|
+
# @example
|
344
|
+
# button_height = my_button.height
|
345
|
+
#
|
346
|
+
def height
|
347
|
+
obj, type = find_element(false)
|
348
|
+
object_not_found_exception(obj, type)
|
349
|
+
obj.get_height
|
350
|
+
end
|
351
|
+
|
352
|
+
# Return x coordinate of object's location.
|
353
|
+
#
|
354
|
+
# @return [Integer]
|
355
|
+
# @example
|
356
|
+
# button_x = my_button.x
|
357
|
+
#
|
358
|
+
def x
|
359
|
+
obj, type = find_element(false)
|
360
|
+
object_not_found_exception(obj, type)
|
361
|
+
obj.get_x
|
362
|
+
end
|
363
|
+
|
364
|
+
# Return y coordinate of object's location.
|
365
|
+
#
|
366
|
+
# @return [Integer]
|
367
|
+
# @example
|
368
|
+
# button_y = my_button.y
|
369
|
+
#
|
370
|
+
def y
|
371
|
+
obj, type = find_element(false)
|
372
|
+
object_not_found_exception(obj, type)
|
373
|
+
obj.get_y
|
374
|
+
end
|
375
|
+
|
376
|
+
# Is UI object displayed in browser window?
|
377
|
+
#
|
378
|
+
# @return [Boolean]
|
379
|
+
# @example
|
380
|
+
# basket_link.displayed??
|
381
|
+
#
|
382
|
+
def displayed?
|
383
|
+
obj, type = find_element(false)
|
384
|
+
object_not_found_exception(obj, type)
|
385
|
+
obj.displayed?
|
386
|
+
end
|
387
|
+
|
388
|
+
def get_value(visible = true)
|
389
|
+
obj, type = find_element(visible)
|
390
|
+
object_not_found_exception(obj, type)
|
391
|
+
case obj.tag_name.downcase
|
392
|
+
when 'input', 'select', 'textarea'
|
393
|
+
obj.value
|
394
|
+
else
|
395
|
+
obj.text
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
alias get_caption get_value
|
400
|
+
|
401
|
+
def verify_value(expected, enqueue = false)
|
402
|
+
actual = get_value
|
403
|
+
enqueue ?
|
404
|
+
ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected UI #{object_ref_message}") :
|
405
|
+
assert_equal(expected.strip, actual.strip, "Expected UI #{object_ref_message} to display '#{expected}' but found '#{actual}'")
|
406
|
+
end
|
407
|
+
|
408
|
+
alias verify_caption verify_value
|
409
|
+
|
410
|
+
# Hover the cursor over an object
|
411
|
+
#
|
412
|
+
# @example
|
413
|
+
# basket_link.hover
|
414
|
+
#
|
415
|
+
def hover
|
416
|
+
obj, type = find_element
|
417
|
+
object_not_found_exception(obj, type)
|
418
|
+
obj.hover
|
419
|
+
end
|
420
|
+
|
421
|
+
def drag_by(right_offset, down_offset)
|
422
|
+
obj, type = find_element
|
423
|
+
object_not_found_exception(obj, type)
|
424
|
+
page.driver.browser.action.click_and_hold(obj.native).perform
|
425
|
+
sleep(1)
|
426
|
+
obj.drag_by(right_offset, down_offset)
|
427
|
+
end
|
428
|
+
|
429
|
+
def drag_and_drop(target, right_offset = nil, down_offset = nil)
|
430
|
+
source, type = find_element
|
431
|
+
object_not_found_exception(source, type)
|
432
|
+
page.driver.browser.action.click_and_hold(source.native).perform
|
433
|
+
sleep(1)
|
434
|
+
target_drop, = target.find_element
|
435
|
+
page.driver.browser.action.move_to(target_drop.native, right_offset.to_i, down_offset.to_i).release.perform
|
436
|
+
end
|
437
|
+
|
438
|
+
def get_attribute(attrib)
|
439
|
+
obj, type = find_element(false)
|
440
|
+
object_not_found_exception(obj, type)
|
441
|
+
obj[attrib]
|
442
|
+
end
|
443
|
+
|
444
|
+
def get_native_attribute(attrib)
|
445
|
+
obj, type = find_element(false)
|
446
|
+
object_not_found_exception(obj, type)
|
447
|
+
obj.native.attribute(attrib)
|
448
|
+
end
|
449
|
+
|
450
|
+
private
|
451
|
+
|
452
|
+
def find_element(visible = true)
|
453
|
+
wait = Selenium::WebDriver::Wait.new(timeout: Capybara.default_max_wait_time)
|
454
|
+
wait.until { find_object(visible) }
|
455
|
+
end
|
456
|
+
|
457
|
+
def find_object(visible = true)
|
458
|
+
@alt_locator.nil? ? obj_locator = @locator : obj_locator = @alt_locator
|
459
|
+
parent_section = @context == :section && !@parent.get_locator.nil?
|
460
|
+
parent_section ? tries ||= 2 : tries ||= 1
|
461
|
+
|
462
|
+
if parent_section && tries > 1
|
463
|
+
parent_locator = @parent.get_locator
|
464
|
+
parent_locator = parent_locator.gsub('|', ' ')
|
465
|
+
parent_locator_type = @parent.get_locator_type
|
466
|
+
obj = page.find(parent_locator_type, parent_locator, :wait => 0.01).find(@locator_type, obj_locator, :wait => 0.01, :visible => visible)
|
467
|
+
else
|
468
|
+
obj = page.find(@locator_type, obj_locator, :wait => 0.01, :visible => visible)
|
469
|
+
end
|
470
|
+
[obj, @locator_type]
|
471
|
+
rescue
|
472
|
+
retry if (tries -= 1) > 0
|
473
|
+
[nil, nil]
|
474
|
+
end
|
475
|
+
|
476
|
+
def object_not_found_exception(obj, obj_type)
|
477
|
+
@alt_locator.nil? ? locator = @locator : locator = @alt_locator
|
478
|
+
obj_type.nil? ? object_type = 'Object' : object_type = obj_type
|
479
|
+
raise "#{object_type} named '#{@name}' (#{locator}) not found" unless obj
|
480
|
+
end
|
481
|
+
|
482
|
+
def invalid_object_type_exception(obj, obj_type)
|
483
|
+
unless obj.tag_name == obj_type || obj.native.attribute('type') == obj_type
|
484
|
+
@alt_locator.nil? ? locator = @locator : locator = @alt_locator
|
485
|
+
raise "#{locator} is not a #{obj_type} element"
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
def invoke_siebel_popup
|
490
|
+
obj, = find_element
|
491
|
+
object_not_found_exception(obj, 'Siebel object')
|
492
|
+
trigger_name = obj.native.attribute('aria-describedby').strip
|
493
|
+
trigger = "span##{trigger_name}"
|
494
|
+
trigger = "#{@parent.get_locator} #{trigger}" if @context == :section && !@parent.get_locator.nil?
|
495
|
+
first(trigger).click
|
496
|
+
end
|
497
|
+
|
498
|
+
def object_ref_message
|
499
|
+
"object '#{get_name}' (#{get_locator})"
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|