Module: Testimonium::Find
- Included in:
- Testimonium
- Defined in:
- lib/testimonium/find_functions.rb
Overview
Find functions
Instance Method Summary collapse
-
#find_all_elements_by_id(id_string, timeout = 2, retries = 5) ⇒ Object
Needs app package name set as const.
-
#find_element_by_id(id_string, timeout = 2, retries = 5) ⇒ Object
Find element by element id.
-
#find_element_by_resourceid(id, timeout = 2, retries = 5) ⇒ Object
Android only: Needs app package name set as const.
-
#find_element_by_text(text_string, timeout = 2, retries = 5) ⇒ Object
Find element by text.
-
#find_element_by_xpath(path, timeout = 3, retries = 5) ⇒ Object
Find element by xpath.
Instance Method Details
#find_all_elements_by_id(id_string, timeout = 2, retries = 5) ⇒ Object
Needs app package name set as const. ANDROID_PACKAGE
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/testimonium/find_functions.rb', line 52 def find_all_elements_by_id(id_string, timeout = 2, retries = 5) list = nil retries.times do sleep timeout begin list = ids(id_string) if device_android list = find_elements(:id, id_string) if device_ios rescue Selenium::WebDriver::Error::NoSuchElementError end return list if list end false end |
#find_element_by_id(id_string, timeout = 2, retries = 5) ⇒ Object
Find element by element id
29 30 31 |
# File 'lib/testimonium/find_functions.rb', line 29 def find_element_by_id(id_string, timeout = 2, retries = 5) find_element_id(id_string, timeout, retries) end |
#find_element_by_resourceid(id, timeout = 2, retries = 5) ⇒ Object
Android only: Needs app package name set as const. ANDROID_PACKAGE
42 43 44 45 46 47 48 49 |
# File 'lib/testimonium/find_functions.rb', line 42 def find_element_by_resourceid(id, timeout = 2, retries = 5) if defined?(ANDROID_PACKAGE).nil? log('ANDROID_PACKAGE variable is missing.') raise Selenium::WebDriver::Error::NoSuchElementError end find_element_by_xpath("//*[@resource-id='#{ANDROID_PACKAGE}:id/#{id}']", timeout, retries) end |
#find_element_by_text(text_string, timeout = 2, retries = 5) ⇒ Object
Find element by text
34 35 36 37 38 39 |
# File 'lib/testimonium/find_functions.rb', line 34 def find_element_by_text(text_string, timeout = 2, retries = 5) if device_android return find_element_by_xpath("//*[@text='#{text_string}']", timeout, retries) end return find_text_ios(text_string, timeout, retries) if device_ios end |
#find_element_by_xpath(path, timeout = 3, retries = 5) ⇒ Object
Find element by xpath
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/testimonium/find_functions.rb', line 7 def find_element_by_xpath(path, timeout = 3, retries = 5) element = nil count = 0 retries.times do sleep timeout count += 1 begin element = find_element(:xpath, path) rescue Selenium::WebDriver::Error::NoSuchElementError end log("Found on attempt #{count}") if element return element if element end log("Failed to find: '#{path}'. Number of attempts: #{count}") false end |