Module: Appom::ElementFinder
Instance Method Summary collapse
-
#_all(*find_args) ⇒ Object
Find elements.
-
#_check_has_element(*find_args) ⇒ Object
Check page has or has not elment with find_args If page has element return TRUE else return FALSE.
-
#_find(*find_args) ⇒ Object
Find an element.
-
#find_element_has_text(text, *find_args) ⇒ Object
Find element with has text match with ‘text` value If not find element will raise error.
-
#wait_until(type, *find_args) ⇒ Object
Function is used to check Note: Function WILL NOT RETURN ELEMENT.
-
#wait_until_get_not_empty(*find_args) ⇒ Object
Use wait to get elements Before timeout we will try to find elements until response return array is not empty.
Instance Method Details
#_all(*find_args) ⇒ Object
Find elements
19 20 21 |
# File 'lib/appom/element_finder.rb', line 19 def _all(*find_args) page.find_elements(*find_args) end |
#_check_has_element(*find_args) ⇒ Object
Check page has or has not elment with find_args If page has element return TRUE else return FALSE
25 26 27 28 |
# File 'lib/appom/element_finder.rb', line 25 def _check_has_element(*find_args) elements = page.find_elements(*find_args) return elements.empty? ? false : true end |
#_find(*find_args) ⇒ Object
Find an element
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/appom/element_finder.rb', line 4 def _find(*find_args) wait = Wait.new(timeout: Appom.max_wait_time) wait.until do elements = page.find_elements(*find_args) elements.each do |element| if element.displayed? return element end end raise Appom::ElementsEmptyError, "Not found element displayed" end end |
#find_element_has_text(text, *find_args) ⇒ Object
Find element with has text match with ‘text` value If not find element will raise error
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/appom/element_finder.rb', line 49 def find_element_has_text(text, *find_args) wait = Wait.new(timeout: Appom.max_wait_time) wait.until do elements = page.find_elements(*find_args) elements.each do |element| if element.displayed? && element.text == text return element end raise Appom::ElementsEmptyError, "Not found element with text #{text}" end end end |
#wait_until(type, *find_args) ⇒ Object
Function is used to check Note: Function WILL NOT RETURN ELEMENT
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/appom/element_finder.rb', line 65 def wait_until(type, *find_args) wait = Wait.new(timeout: Appom.max_wait_time) wait.until do case type # Function only return true if element enabled or raise an error if time out when 'element enable' page.find_element(*find_args).enabled? # Function only return true if element disabled or raise an error if time out when 'element disable' !page.find_element(*find_args).enabled? # Function only return true if we can find at leat one element (array is not empty) or raise error when 'at least one element exists' !page.find_elements(*find_args).empty? # Function only return true if we can't find at leat one element (array is empty) or raise error when 'no element exists' page.find_elements(*find_args).empty? end end end |
#wait_until_get_not_empty(*find_args) ⇒ Object
Use wait to get elements Before timeout we will try to find elements until response return array is not empty
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/appom/element_finder.rb', line 34 def wait_until_get_not_empty(*find_args) wait = Wait.new(timeout: Appom.max_wait_time) wait.until do result = page.find_elements(*find_args) # If reponse is empty we will return false to make it not pass Wait condition if result.empty? raise Appom::ElementsEmptyError, "Array is empty" end # Return result return result end end |