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, timeout = 2, retries = 5) ⇒ list
Find all elements with id.
-
#find_element_by_id(id, timeout = 2, retries = 5) ⇒ element
Find element by element id.
-
#find_element_by_resourceid(id, timeout = 2, retries = 5) ⇒ element
Find element by resourceid.
-
#find_element_by_text(text, timeout = 2, retries = 5) ⇒ element
Find element by text.
-
#find_element_by_xpath(path, timeout = 3, retries = 5) ⇒ element
Find element by xpath.
Instance Method Details
#find_all_elements_by_id(id, timeout = 2, retries = 5) ⇒ list
Find all elements with id.
Android needs app package name set as constant ANDROID_PACKAGE.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/testimonium/find_functions.rb', line 79 def find_all_elements_by_id(id, timeout = 2, retries = 5) list = nil count = 0 retries.times do sleep timeout count += 1 begin list = ids(id) if device_android list = find_elements(:id, id) if device_ios rescue Selenium::WebDriver::Error::NoSuchElementError end logger("Found all elements with id '#{id}' on attempt #{count}") if list return list if list end logger("Failed to find elements with id '#{id}'. Number of attempts: #{count}") nil end |
#find_element_by_id(id, timeout = 2, retries = 5) ⇒ element
Find element by element id.
39 40 41 |
# File 'lib/testimonium/find_functions.rb', line 39 def find_element_by_id(id, timeout = 2, retries = 5) find_element_id(id, timeout, retries) end |
#find_element_by_resourceid(id, timeout = 2, retries = 5) ⇒ element
Find element by resourceid.
Android only - Needs app package name set as constant ANDROID_PACKAGE.
62 63 64 65 66 67 68 69 |
# File 'lib/testimonium/find_functions.rb', line 62 def find_element_by_resourceid(id, timeout = 2, retries = 5) if defined?(ANDROID_PACKAGE).nil? logger('ANDROID_PACKAGE is missing.', 'fatal') raise Selenium::WebDriver::Error::NoSuchElementError end find_element_by_xpath("//*[@resource-id='#{ANDROID_PACKAGE}:id/#{id}']", timeout, retries) end |
#find_element_by_text(text, timeout = 2, retries = 5) ⇒ element
Find element by text.
49 50 51 52 |
# File 'lib/testimonium/find_functions.rb', line 49 def find_element_by_text(text, timeout = 2, retries = 5) return find_element_by_xpath("//*[@text='#{text}']", timeout, retries) if device_android return find_text_ios(text, timeout, retries) if device_ios end |
#find_element_by_xpath(path, timeout = 3, retries = 5) ⇒ element
Find element by xpath.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/testimonium/find_functions.rb', line 12 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 logger("Found '#{path}' on attempt #{count}") if element return element if element end logger("Failed to find '#{path}'. Number of attempts: #{count}") nil end |