Class: TestCentricity::AppUIElement
- Inherits:
-
Object
- Object
- TestCentricity::AppUIElement
show all
- Includes:
- Test::Unit::Assertions
- Defined in:
- lib/testcentricity/app_elements/app_element_helper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#clear ⇒ Object
-
#click ⇒ Object
-
#disabled? ⇒ Boolean
-
#double_tap ⇒ Object
-
#enabled? ⇒ Boolean
-
#exists? ⇒ Boolean
-
#get_attribute(attrib) ⇒ Object
-
#get_caption ⇒ Object
(also: #caption)
-
#get_locator ⇒ Object
-
#get_name ⇒ Object
-
#get_object_type ⇒ Object
-
#get_value ⇒ Object
(also: #value)
-
#height ⇒ Integer
-
#hidden? ⇒ Boolean
-
#initialize(name, parent, locator, context) ⇒ AppUIElement
constructor
A new instance of AppUIElement.
-
#scroll(direction) ⇒ Object
-
#selected? ⇒ Boolean
-
#send_keys(value) ⇒ Object
-
#set(value) ⇒ Object
-
#swipe(direction) ⇒ Object
-
#tag_name ⇒ Object
-
#tap ⇒ Object
-
#visible? ⇒ Boolean
-
#wait_until_enabled(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is enabled, or until the specified wait time has expired.
-
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
Wait until the object exists, or until the specified wait time has expired.
-
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
Wait until the object no longer exists, or until the specified wait time has expired.
-
#wait_until_hidden(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is hidden, or until the specified wait time has expired.
-
#wait_until_value_changes(seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value changes to a different value, or until the specified wait time has expired.
-
#wait_until_value_is(value, seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value equals the specified value, or until the specified wait time has expired.
-
#wait_until_visible(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is visible, or until the specified wait time has expired.
-
#width ⇒ Object
-
#x_loc ⇒ Integer
Return x coordinate of object's location.
-
#y_loc ⇒ Integer
Return y coordinate of object's location.
Constructor Details
#initialize(name, parent, locator, context) ⇒ AppUIElement
Returns a new instance of AppUIElement.
9
10
11
12
13
14
15
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 9
def initialize(name, parent, locator, context)
@name = name
@parent = parent
@locator = locator
@context = context
@type = nil
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
7
8
9
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 7
def context
@context
end
|
#locator ⇒ Object
Returns the value of attribute locator.
7
8
9
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 7
def locator
@locator
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 7
def name
@name
end
|
#parent ⇒ Object
Returns the value of attribute parent.
7
8
9
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 7
def parent
@parent
end
|
#type ⇒ Object
Returns the value of attribute type.
7
8
9
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 7
def type
@type
end
|
Instance Method Details
#clear ⇒ Object
70
71
72
73
74
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 70
def clear
obj = element
object_not_found_exception(obj)
obj.clear
end
|
#click ⇒ Object
29
30
31
32
33
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 29
def click
obj = element
object_not_found_exception(obj)
obj.click
end
|
#disabled? ⇒ Boolean
158
159
160
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 158
def disabled?
!enabled?
end
|
#double_tap ⇒ Object
42
43
44
45
46
47
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 42
def double_tap
obj = element
object_not_found_exception(obj)
actions = Appium::TouchAction.new
actions.double_tap(element: obj).perform
end
|
#enabled? ⇒ Boolean
152
153
154
155
156
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 152
def enabled?
obj = element
object_not_found_exception(obj)
obj.enabled?
end
|
#exists? ⇒ Boolean
132
133
134
135
136
137
138
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 132
def exists?
begin
element.displayed?
rescue
false
end
end
|
#get_attribute(attrib) ⇒ Object
174
175
176
177
178
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 174
def get_attribute(attrib)
obj = element
object_not_found_exception(obj)
obj.attribute(attrib)
end
|
#get_caption ⇒ Object
Also known as:
caption
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 93
def get_caption
obj = element
object_not_found_exception(obj)
if AppiumConnect.is_webview?
case obj.tag_name.downcase
when 'input', 'select', 'textarea'
obj.value
else
obj.text
end
elsif Environ.is_ios?
case obj.tag_name
when 'XCUIElementTypeNavigationBar'
obj.attribute(:name)
else
obj.attribute(:label)
end
else
caption = obj.text
if caption.blank?
case obj.attribute(:class)
when 'android.view.ViewGroup'
caption_obj = obj.find_element(:xpath, '//android.widget.TextView')
caption = caption_obj.text
when 'android.widget.Button'
caption_obj = obj.find_element(:xpath, '//android.widget.TextView')
caption = caption_obj.text
if caption.blank?
caption_obj = obj.find_element(:xpath, '//android.widget.ViewGroup/android.widget.TextView')
caption = caption_obj.text
end
end
end
caption
end
end
|
#get_locator ⇒ Object
21
22
23
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 21
def get_locator
@locator
end
|
#get_name ⇒ Object
25
26
27
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 25
def get_name
@name
end
|
#get_object_type ⇒ Object
17
18
19
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 17
def get_object_type
@type
end
|
#get_value ⇒ Object
Also known as:
value
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 76
def get_value
obj = element
object_not_found_exception(obj)
if AppiumConnect.is_webview?
case obj.tag_name.downcase
when 'input', 'select', 'textarea'
obj.value
else
obj.text
end
else
obj.value
end
end
|
#height ⇒ Integer
329
330
331
332
333
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 329
def height
obj = element
object_not_found_exception(obj)
obj.size.height
end
|
#hidden? ⇒ Boolean
148
149
150
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 148
def hidden?
!visible?
end
|
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 359
def scroll(direction)
obj = element
object_not_found_exception(obj)
if Environ.is_ios?
$driver.execute_script('mobile: scroll', { direction: direction })
else
case direction
when :down
x = obj.size.width.to_i / 2
bottom = obj.size.height
bottom = window_size[:height].to_i if bottom > window_size[:height]
start_pt = [x, bottom]
delta_pt = [0, 0 - (bottom - 20)]
when :up
x = obj.size.width.to_i / 2
top = obj.location.y - (obj.size.height / 2)
top = 0 if top < 0
start_pt = [x, top]
delta_pt = [0, obj.size.height / 2]
end
puts "Swipe start_pt = #{start_pt} / delta_pt = #{delta_pt}" if ENV['DEBUG']
Appium::TouchAction.new.swipe(start_x: start_pt[0], start_y: start_pt[1], delta_x: delta_pt[0], delta_y: delta_pt[1]).perform
end
end
|
#selected? ⇒ Boolean
162
163
164
165
166
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 162
def selected?
obj = element
object_not_found_exception(obj)
obj.selected?
end
|
#send_keys(value) ⇒ Object
64
65
66
67
68
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 64
def send_keys(value)
obj = element
object_not_found_exception(obj)
obj.send_keys(value)
end
|
#set(value) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 49
def set(value)
obj = element
object_not_found_exception(obj)
if value.is_a?(Array)
obj.send_keys(value[0])
if value[1].is_a?(Integer)
press_keycode(value[1])
else
obj.send_keys(value[1])
end
elsif value.is_a?(String)
obj.send_keys(value)
end
end
|
#swipe(direction) ⇒ Object
385
386
387
388
389
390
391
392
393
394
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 385
def swipe(direction)
obj = element
object_not_found_exception(obj)
if Environ.is_ios?
$driver.execute_script('mobile: swipe', direction: direction.to_s, element: obj)
else
actions = Appium::TouchAction.new
actions.scroll(element: obj).perform
end
end
|
#tag_name ⇒ Object
168
169
170
171
172
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 168
def tag_name
obj = element
object_not_found_exception(obj)
obj.tag_name
end
|
#tap ⇒ Object
35
36
37
38
39
40
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 35
def tap
obj = element
object_not_found_exception(obj)
actions = Appium::TouchAction.new
actions.tap(element: obj).perform
end
|
#visible? ⇒ Boolean
140
141
142
143
144
145
146
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 140
def visible?
if exists?
element.displayed?
else
false
end
end
|
#wait_until_enabled(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is enabled, or until the specified wait time has expired. If the wait time is nil, then the
wait time will be Environ.default_max_wait_time.
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 263
def wait_until_enabled(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { enabled? }
rescue
if post_exception
raise "UI #{object_ref_message} remained disabled after #{timeout} seconds" unless enabled?
else
enabled?
end
end
|
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
Wait until the object exists, or until the specified wait time has expired. If the wait time is nil, then the wait
time will be Environ.default_max_wait_time.
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 187
def wait_until_exists(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { exists? }
rescue
if post_exception
raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless exists?
else
exists?
end
end
|
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
Wait until the object no longer exists, or until the specified wait time has expired. If the wait time is nil, then
the wait time will be Environ.default_max_wait_time.
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 206
def wait_until_gone(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { !exists? }
rescue
if post_exception
raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if exists?
else
exists?
end
end
|
#wait_until_hidden(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is hidden, or until the specified wait time has expired. If the wait time is nil, then the
wait time will be Environ.default_max_wait_time.
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 244
def wait_until_hidden(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { hidden? }
rescue
if post_exception
raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if visible?
else
hidden?
end
end
|
#wait_until_value_changes(seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value changes to a different value, or until the specified wait time has expired. If the
wait time is nil, then the wait time will be Environ.default_max_wait_time.
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 304
def wait_until_value_changes(seconds = nil, post_exception = true)
value = get_value
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { get_value != value }
rescue
if post_exception
raise "Value of UI #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_value == value
else
get_value == value
end
end
|
#wait_until_value_is(value, seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value equals the specified value, or until the specified wait time has expired. If the wait
time is nil, then the wait time will be Environ.default_max_wait_time.
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 285
def wait_until_value_is(value, seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { compare(value, get_value) }
rescue
if post_exception
raise "Value of UI #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value
else
get_value == value
end
end
|
#wait_until_visible(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is visible, or until the specified wait time has expired. If the wait time is nil, then the
wait time will be Environ.default_max_wait_time.
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 225
def wait_until_visible(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { visible? }
rescue
if post_exception
raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless visible?
else
visible?
end
end
|
#width ⇒ Object
317
318
319
320
321
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 317
def width
obj = element
object_not_found_exception(obj)
obj.size.width
end
|
#x_loc ⇒ Integer
Return x coordinate of object's location.
341
342
343
344
345
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 341
def x_loc
obj = element
object_not_found_exception(obj)
obj.location.x
end
|
#y_loc ⇒ Integer
Return y coordinate of object's location.
353
354
355
356
357
|
# File 'lib/testcentricity/app_elements/app_element_helper.rb', line 353
def y_loc
obj = element
object_not_found_exception(obj)
obj.location.y
end
|