Module: Appium::Ios::Xcuitest::Helper

Defined in:
lib/appium_lib/ios/xcuitest/helper.rb

Instance Method Summary collapse

Instance Method Details

#last_ele(class_name) ⇒ Element

Get the last tag that matches class_name

Parameters:

  • class_name (String)

    the tag to match

Returns:



40
41
42
43
44
45
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 40

def last_ele(class_name)
  visible_elements = tags class_name
  raise _no_such_element if visible_elements.empty?

  visible_elements.last
end

#string_attr_exact(class_name, attr, value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 20

def string_attr_exact(class_name, attr, value)
  if attr == '*'
    %((//#{class_name})[@*[.="#{value}"]])
  else
    %((//#{class_name})[@#{attr}="#{value}"])
  end
end

#string_attr_include(class_name, attr, value) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 29

def string_attr_include(class_name, attr, value)
  if attr == '*'
    %((//#{class_name})[@*[contains(translate(., "#{value.upcase}", "#{value}"), "#{value}")]])
  else
    %((//#{class_name})[contains(translate(@#{attr}, "#{value.upcase}", "#{value}"), "#{value}")])
  end
end

#tag(class_name) ⇒ Element

Returns the first visible element matching class_name

Parameters:

  • class_name (String)

    the class_name to search for

Returns:



51
52
53
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 51

def tag(class_name)
  raise_error_if_no_element tags(class_name).first
end

#tags(class_name) ⇒ Element

Returns all visible elements matching class_name

Parameters:

  • class_name (String)

    the class_name to search for

Returns:



59
60
61
62
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 59

def tags(class_name)
  elements = @driver.find_elements :class, class_name
  select_visible_elements elements
end

#tags_exact(class_names:, value: nil) ⇒ Array[Element]

Returns all visible elements matching class_names and value. This method calls find_element/s and element.value/text many times. So, if you set many class_names, this method’s performance become worse.

Parameters:

  • class_names (Array[String])

    the class_names to search for

  • value (String) (defaults to: nil)

    the value to search for

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 93

def tags_exact(class_names:, value: nil)
  return unless class_names.is_a? Array

  c_names = class_names.map { |class_name| %(type == "#{class_name}") }.join(' || ')

  predicate = if value
                %((#{c_names}) && (name ==[c] "#{value}" || label ==[c] "#{value}" || value ==[c] "#{value}"))
              else
                c_names
              end

  elements = @driver.find_elements :predicate, predicate
  select_visible_elements elements
end

#tags_include(class_names:, value: nil) ⇒ Array[Element]

Returns all visible elements matching class_names and value This method calls find_element/s and element.value/text many times. So, if you set many class_names, this method’s performance become worse.

Parameters:

  • class_names (Array[String])

    the class_names to search for

  • value (String) (defaults to: nil)

    the value to search for

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/appium_lib/ios/xcuitest/helper.rb', line 71

def tags_include(class_names:, value: nil)
  return unless class_names.is_a? Array

  c_names = class_names.map { |class_name| %(type == "#{class_name}") }.join(' || ')

  predicate = if value
                %((#{c_names}) && (name contains[c] "#{value}" || label contains[c] "#{value}" || value contains[c] "#{value}")) # rubocop:disable Layout/LineLength
              else
                c_names
              end

  elements = @driver.find_elements :predicate, predicate
  select_visible_elements elements
end