Module: Appium::Android::Uiautomator2::Helper

Defined in:
lib/appium_lib/android/uiautomator2/helper.rb

Instance Method Summary collapse

Instance Method Details

#complex_find_contains(class_name, value) ⇒ Element

Find the first element that contains value

Parameters:

  • class_name (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:



31
32
33
34
35
36
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 31

def complex_find_contains(class_name, value)
  elements = find_elements :uiautomator, string_visible_contains(class_name, value)
  raise _no_such_element if elements.empty?

  elements.first
end

#complex_find_exact(class_name, value) ⇒ Element

Find the first element exactly matching value

Parameters:

  • class_name (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:



70
71
72
73
74
75
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 70

def complex_find_exact(class_name, value)
  elements = find_elements :uiautomator, string_visible_exact(class_name, value)
  raise _no_such_element if elements.empty?

  elements.first
end

#complex_finds_contains(class_name, value) ⇒ Array<Element>

Find all elements containing value

Parameters:

  • class_name (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:



42
43
44
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 42

def complex_finds_contains(class_name, value)
  find_elements :uiautomator, string_visible_contains(class_name, value)
end

#complex_finds_exact(class_name, value) ⇒ Element

Find all elements exactly matching value

Parameters:

  • class_name (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:



81
82
83
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 81

def complex_finds_exact(class_name, value)
  find_elements :uiautomator, string_visible_exact(class_name, value)
end

#string_visible_contains(class_name, value) ⇒ String

Returns a string that matches the first element that contains value For automationName is Appium example: string_visible_contains ‘UIATextField’, ‘sign in’ note for XPath: github.com/appium/ruby_lib/pull/561

Parameters:

  • class_name (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (String)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 13

def string_visible_contains(class_name, value)
  value = %("#{value}")
  if class_name == '*'
    return (resource_id(value, "new UiSelector().resourceId(#{value});") +
      "new UiSelector().descriptionContains(#{value});" \
      "new UiSelector().textContains(#{value});")
  end

  class_name = %("#{class_name}")
  resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
    "new UiSelector().className(#{class_name}).descriptionContains(#{value});" \
    "new UiSelector().className(#{class_name}).textContains(#{value});"
end

#string_visible_exact(class_name, value) ⇒ String

Create an string to exactly match the first element with target value

Parameters:

  • class_name (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (String)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 51

def string_visible_exact(class_name, value)
  value = %("#{value}")

  if class_name == '*'
    return (resource_id(value, "new UiSelector().resourceId(#{value});") +
      "new UiSelector().description(#{value});" \
      "new UiSelector().text(#{value});")
  end

  class_name = %("#{class_name}")
  resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
    "new UiSelector().className(#{class_name}).description(#{value});" \
    "new UiSelector().className(#{class_name}).text(#{value});"
end