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:



45
46
47
48
49
50
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 45

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:



84
85
86
87
88
89
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 84

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:



56
57
58
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 56

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:



95
96
97
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 95

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)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 27

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)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/appium_lib/android/uiautomator2/helper.rb', line 65

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