Skip to content

Commit 7c77faa

Browse files
Add exists method
Fix #2
1 parent 27f4ccf commit 7c77faa

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

lib/appium_lib/console.rb

+36-1
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,43 @@ def set_wait timeout=$default_wait
167167
$driver.manage.timeouts.implicit_wait = timeout
168168
end
169169

170+
# Returns the default client side wait.
171+
# This value is independent of what the server is using
172+
# @return [Integer]
173+
def get_wait
174+
$default_wait
175+
end
176+
177+
# Returns existance of element.
178+
#
179+
# Example:
180+
#
181+
# exists { button('sign in') } ? puts('true') : puts('false')
182+
#
183+
# @return [Boolean]
184+
def exists &search_block
185+
pre_check = 0
186+
post_check = $default_wait
187+
188+
set_wait pre_check # set wait to zero
189+
190+
# the element exists unless an error is raised.
191+
exists = true
192+
193+
begin
194+
search_block.call # search for element
195+
rescue
196+
exists = false # error means it's not there
197+
end
198+
199+
# restore wait
200+
set_wait post_check
201+
202+
return exists
203+
end
204+
170205
# The same as $driver.execute_script
171-
# @return the object returned by execute_script
206+
# @return [Object] the object returned by execute_script
172207
def execute_script script, *args
173208
$driver.execute_script script, *args
174209
end

0 commit comments

Comments
 (0)