Module: Appium::Ios

Defined in:
lib/appium_lib/ios/ios.rb,
lib/appium_lib/ios/xcuitest.rb,
lib/appium_lib/ios/element/text.rb,
lib/appium_lib/ios/common/errors.rb,
lib/appium_lib/ios/common/helper.rb,
lib/appium_lib/ios/element/alert.rb,
lib/appium_lib/ios/element/button.rb,
lib/appium_lib/ios/element/generic.rb,
lib/appium_lib/ios/xcuitest/bridge.rb,
lib/appium_lib/ios/xcuitest/helper.rb,
lib/appium_lib/ios/xcuitest/command.rb,
lib/appium_lib/ios/xcuitest/element.rb,
lib/appium_lib/ios/element/textfield.rb,
lib/appium_lib/ios/xcuitest/element/text.rb,
lib/appium_lib/ios/xcuitest/command/source.rb,
lib/appium_lib/ios/xcuitest/element/button.rb,
lib/appium_lib/ios/xcuitest/element/generic.rb,
lib/appium_lib/ios/xcuitest/command/gestures.rb,
lib/appium_lib/ios/xcuitest/element/textfield.rb,
lib/appium_lib/ios/xcuitest/command/pasteboard.rb,
lib/appium_lib/ios/xcuitest/command/certificate.rb,
lib/appium_lib/ios/xcuitest/command/get_context.rb,
lib/appium_lib/ios/xcuitest/command/multi_app_handler.rb

Defined Under Namespace

Modules: Xcuitest Classes: Bridge, CommandError, UITestElementsPrinter

Constant Summary collapse

UIA_STATIC_TEXT =
'UIAStaticText'
UIAStaticText =
UIA_STATIC_TEXT
XCUIELEMENT_TYPE_STATIC_TEXT =
'XCUIElementTypeStaticText'
XCUIElementTypeStaticText =
XCUIELEMENT_TYPE_STATIC_TEXT
UIA_BUTTON =
'UIAButton'
UIAButton =
UIA_BUTTON
XCUIELEMENT_TYPE_BUTTON =
'XCUIElementTypeButton'
XCUIElementTypeButton =
XCUIELEMENT_TYPE_BUTTON
UIA_TEXT_FIELD =
'UIATextField'
UIATextField =
UIA_TEXT_FIELD
UIA_SECURE_TEXT_FIELD =
'UIASecureTextField'
UIASecureTextField =
UIA_SECURE_TEXT_FIELD
XCUIELEMENT_TYPE_TEXT_FIELD =
'XCUIElementTypeTextField'
XCUIElementTypeTextField =
XCUIELEMENT_TYPE_TEXT_FIELD
XCUIELEMENT_TYPE_SECURE_TEXT_FIELD =
'XCUIElementTypeSecureTextField'
XCUIElementTypeSecureTextField =
XCUIELEMENT_TYPE_SECURE_TEXT_FIELD

Instance Method Summary collapse

Instance Method Details

#_all_pred(opts) ⇒ Object

predicate - the predicate to evaluate on the main app

visible - if true, only visible elements are returned. default true

Raises:



377
378
379
380
381
382
383
# File 'lib/appium_lib/ios/common/helper.rb', line 377

def _all_pred(opts)
  predicate = opts[:predicate]
  raise ArgumentError, 'predicate must be provided' unless predicate

  visible = opts.fetch :visible, true
  %($.mainApp().getAllWithPredicate("#{predicate}", #{visible});)
end

#_by_json(opts) ⇒ Object

For Appium(automation name), not XCUITest typeArray - array of string types to search for. Example: [“UIAStaticText”] onlyFirst - boolean. returns only the first result if true. Example: true onlyVisible - boolean. returns only visible elements if true. Example: true target - string. the target value to search for. Example: “Buttons, Various uses of UIButton” substring - boolean. matches on substrings if true otherwise an exact mathc is required. Example: true insensitive - boolean. ignores case sensitivity if true otherwise it’s case sensitive. Example: true

opts = {

typeArray: ["UIAStaticText"],
onlyFirst: true,
onlyVisible: true,
name: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
},
label: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
},
value: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
}

}

Raises:



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/appium_lib/ios/common/helper.rb', line 456

def _by_json(opts)
  valid_keys = %i(typeArray onlyFirst onlyVisible name label value)
  unknown_keys = opts.keys - valid_keys
  raise ArgumentError, "Unknown keys: #{unknown_keys}" unless unknown_keys.empty?

  type_array = opts[:typeArray]
  raise ArgumentError, 'typeArray must be an array' unless type_array.is_a? Array

  only_first = opts[:onlyFirst]
  raise ArgumentError, 'onlyFirst must be a boolean' unless [true, false].include? only_first

  only_visible = opts[:onlyVisible]
  raise ArgumentError, 'onlyVisible must be a boolean' unless [true, false].include? only_visible

  # name/label/value are optional. when searching for class only, then none
  # will be present.
  _validate_object opts[:name], opts[:label], opts[:value]

  # NOTE: that mainWindow is sometimes nil so it's passed as a param
  # $._elementOrElementsByType will validate that the window isn't nil
  element_or_elements_by_type = <<-JS
    (function() {
      var opts = #{opts.to_json};
      var result = false;

      try {
        result = $._elementOrElementsByType($.mainWindow(), opts);
      } catch (e) {
      }

      return result;
    })();
  JS

  res = execute_script element_or_elements_by_type
  res || raise(Appium::Ios::CommandError, 'mainWindow is nil')
end

#_validate_object(*objects) ⇒ Object

Raises:



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/appium_lib/ios/common/helper.rb', line 406

def _validate_object(*objects)
  raise ArgumentError, 'objects must be an array' unless objects.is_a? Array

  objects.each do |obj|
    next unless obj # obj may be nil. if so, ignore.

    valid_keys   = %i[target substring insensitive]
    unknown_keys = obj.keys - valid_keys
    raise ArgumentError, "Unknown keys: #{unknown_keys}" unless unknown_keys.empty?

    target = obj[:target]
    raise ArgumentError, 'target must be a string' unless target.is_a? String

    substring = obj[:substring]
    raise ArgumentError, 'substring must be a boolean' unless [true, false].include? substring

    insensitive = obj[:insensitive]
    raise ArgumentError, 'insensitive must be a boolean' unless [true, false].include? insensitive
  end
end

#alert_acceptvoid

This method returns an undefined value.

Accept the alert.



19
20
21
22
23
# File 'lib/appium_lib/ios/element/alert.rb', line 19

def alert_accept
  # @driver.switch_to.alert.accept
  # ".switch_to.alert" calls alert_text so use bridge directly
  driver.send(:bridge).accept_alert
end

#alert_dismissvoid

This method returns an undefined value.

Dismiss the alert.



27
28
29
30
31
# File 'lib/appium_lib/ios/element/alert.rb', line 27

def alert_dismiss
  # @driver.switch_to.alert.dismiss
  # ".switch_to.alert" calls alert_text so use bridge directly
  driver.send(:bridge).dismiss_alert
end

#button(value) ⇒ UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

Find the first UIAButton|XCUIElementTypeButton that contains value or by index. If int then the UIAButton|XCUIElementTypeButton at that index is returned.

Parameters:

  • value (String, Integer)

    the value to exactly match.

Returns:



33
34
35
36
37
38
# File 'lib/appium_lib/ios/element/button.rb', line 33

def button(value)
  # return button at index.
  return ele_index button_class, value if value.is_a? Numeric

  ele_by_json_visible_contains button_class, value
end

#button_classString

Returns Class name for button.

Returns:

  • (String)

    Class name for button



25
26
27
# File 'lib/appium_lib/ios/element/button.rb', line 25

def button_class
  UIA_BUTTON
end

#button_exact(value) ⇒ UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

Find the first UIAButton|XCUIElementTypeButton that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



67
68
69
# File 'lib/appium_lib/ios/element/button.rb', line 67

def button_exact(value)
  ele_by_json_visible_exact button_class, value
end

#buttons(value = false) ⇒ Array<UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON>

Find all UIAButtons|XCUIElementTypeButtons containing value. If value is omitted, all UIAButtons|XCUIElementTypeButtons are returned.

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:



44
45
46
47
48
# File 'lib/appium_lib/ios/element/button.rb', line 44

def buttons(value = false)
  return tags button_class unless value

  eles_by_json_visible_contains button_class, value
end

#buttons_exact(value) ⇒ Array<UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON>

Find all UIAButtons|XCUIElementTypeButtons that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



74
75
76
# File 'lib/appium_lib/ios/element/button.rb', line 74

def buttons_exact(value)
  eles_by_json_visible_exact button_class, value
end

#ele_by_json(opts) ⇒ Object

see eles_by_json



512
513
514
515
516
517
518
# File 'lib/appium_lib/ios/common/helper.rb', line 512

def ele_by_json(opts)
  opts[:onlyFirst] = true
  result = _by_json(opts).first
  raise _no_such_element if result.nil?

  result
end

#ele_by_json_visible_contains(element, value) ⇒ Element

Find the first element that contains value. For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Element)


320
321
322
# File 'lib/appium_lib/ios/common/helper.rb', line 320

def ele_by_json_visible_contains(element, value)
  ele_by_json string_visible_contains element, value
end

#ele_by_json_visible_exact(element, value) ⇒ Element

Find the first element exactly matching value For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Element)


359
360
361
# File 'lib/appium_lib/ios/common/helper.rb', line 359

def ele_by_json_visible_exact(element, value)
  ele_by_json string_visible_exact element, value
end

#ele_index(class_name, index) ⇒ Element

Get the element of type class_name at matching index.

Parameters:

  • class_name (String)

    the class name to find

  • index (Integer)

    the index

Returns:

  • (Element)

Raises:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/appium_lib/ios/common/helper.rb', line 109

def ele_index(class_name, index)
  raise ArgumentError, 'Index must be >= 1' unless index == 'last()' || (index.is_a?(Integer) && index >= 1)

  elements = tags(class_name)

  if index == 'last()'
    result = elements.last
  else
    # elements array is 0 indexed
    index -= 1
    result = elements[index]
  end

  raise _no_such_element if result.nil?

  result
end

#ele_with_pred(opts) ⇒ Element

returns element matching predicate contained in the main app

predicate - the predicate to evaluate on the main app

visible - if true, only visible elements are returned. default true

Returns:

  • (Element)


391
392
393
394
# File 'lib/appium_lib/ios/common/helper.rb', line 391

def ele_with_pred(opts)
  # true = return only visible
  find_element(:uiautomation, _all_pred(opts))
end

#eles_by_json(opts) ⇒ Object

For Appium(automation name), not XCUITest example usage:

eles_by_json({

typeArray: ["UIAStaticText"],
onlyVisible: true,
name: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
},

})



506
507
508
509
# File 'lib/appium_lib/ios/common/helper.rb', line 506

def eles_by_json(opts)
  opts[:onlyFirst] = false
  _by_json opts
end

#eles_by_json_visible_contains(element, value) ⇒ Array<Element>

Find all elements containing value For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Array<Element>)


329
330
331
# File 'lib/appium_lib/ios/common/helper.rb', line 329

def eles_by_json_visible_contains(element, value)
  eles_by_json string_visible_contains element, value
end

#eles_by_json_visible_exact(element, value) ⇒ Element

Find all elements exactly matching value For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Element)


368
369
370
# File 'lib/appium_lib/ios/common/helper.rb', line 368

def eles_by_json_visible_exact(element, value)
  eles_by_json string_visible_exact element, value
end

#eles_with_pred(opts) ⇒ Array<Element>

returns elements matching predicate contained in the main app

predicate - the predicate to evaluate on the main app

visible - if true, only visible elements are returned. default true

Returns:

  • (Array<Element>)


402
403
404
# File 'lib/appium_lib/ios/common/helper.rb', line 402

def eles_with_pred(opts)
  find_elements(:uiautomation, _all_pred(opts))
end

#find(value) ⇒ Element

Find the first element containing value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Element)


20
21
22
# File 'lib/appium_lib/ios/element/generic.rb', line 20

def find(value)
  ele_by_json_visible_contains '*', value
end

#find_ele_by_attr(class_name, attr, value) ⇒ Element

Find the first element exactly matching class and attribute value. Note: Uses XPath Note: For XCUITest, this method return ALL elements include displayed or not displayed elements.

Parameters:

  • class_name (String)

    the class name to search for

  • attr (String)

    the attribute to inspect

  • value (String)

    the expected value of the attribute

Returns:

  • (Element)


139
140
141
# File 'lib/appium_lib/ios/common/helper.rb', line 139

def find_ele_by_attr(class_name, attr, value)
  @driver.find_element :xpath, string_attr_exact(class_name, attr, value)
end

#find_ele_by_attr_include(class_name, attr, value) ⇒ Element

Get the first tag by attribute that exactly matches value. Note: Uses XPath

Parameters:

  • class_name (String)

    the tag name to match

  • attr (String)

    the attribute to compare

  • value (String)

    the value of the attribute that the element must include

Returns:

  • (Element)

    the element of type tag who’s attribute includes value



191
192
193
# File 'lib/appium_lib/ios/common/helper.rb', line 191

def find_ele_by_attr_include(class_name, attr, value)
  @driver.find_element :xpath, string_attr_include(class_name, attr, value)
end

#find_ele_by_predicate(class_name: '*', value:) ⇒ Element

Find the first element exactly matching attribute case insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the expected value of the attribute

Returns:

  • (Element)


163
164
165
166
167
168
# File 'lib/appium_lib/ios/common/helper.rb', line 163

def find_ele_by_predicate(class_name: '*', value:)
  elements = find_eles_by_predicate(class_name: class_name, value: value)
  raise _no_such_element if elements.empty?

  elements.first
end

#find_ele_by_predicate_include(class_name: '*', value:) ⇒ Element

Get the first elements that include insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the value of the attribute that the element must include

Returns:

  • (Element)

    the element of type tag who’s attribute includes value



209
210
211
212
213
214
# File 'lib/appium_lib/ios/common/helper.rb', line 209

def find_ele_by_predicate_include(class_name: '*', value:)
  elements = find_eles_by_predicate_include(class_name: class_name, value: value)
  raise _no_such_element if elements.empty?

  elements.first
end

#find_eles_by_attr(class_name, attr, value) ⇒ Array<Element>

Find all elements exactly matching class and attribute value. Note: Uses XPath Note: For XCUITest, this method return ALL elements include displayed or not displayed elements.

Parameters:

  • class_name (String)

    the class name to match

  • attr (String)

    the attribute to compare

  • value (String)

    the value of the attribute that the element must have

Returns:

  • (Array<Element>)


150
151
152
# File 'lib/appium_lib/ios/common/helper.rb', line 150

def find_eles_by_attr(class_name, attr, value)
  @driver.find_elements :xpath, string_attr_exact(class_name, attr, value)
end

#find_eles_by_attr_include(class_name, attr, value) ⇒ Array<Element>

Get tags by attribute that include value. Note: Uses XPath

Parameters:

  • class_name (String)

    the tag name to match

  • attr (String)

    the attribute to compare

  • value (String)

    the value of the attribute that the element must include

Returns:

  • (Array<Element>)

    the elements of type tag who’s attribute includes value



201
202
203
# File 'lib/appium_lib/ios/common/helper.rb', line 201

def find_eles_by_attr_include(class_name, attr, value)
  @driver.find_elements :xpath, string_attr_include(class_name, attr, value)
end

#find_eles_by_predicate(class_name: '*', value:) ⇒ Array<Element>

Find all elements exactly matching attribute case insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the value of the attribute that the element must have

  • class_name (String) (defaults to: '*')

    the tag name to match

Returns:

  • (Array<Element>)


175
176
177
178
179
180
181
182
183
# File 'lib/appium_lib/ios/common/helper.rb', line 175

def find_eles_by_predicate(class_name: '*', value:)
  predicate = if class_name == '*'
                %(name == "#{value}" || label == "#{value}" || value == "#{value}")
              else
                %(type == "#{class_name}" && ) +
                  %((name == "#{value}" || label == "#{value}" || value == "#{value}"))
              end
  @driver.find_elements :predicate, predicate
end

#find_eles_by_predicate_include(class_name: '*', value:) ⇒ Array<Element>

Get elements that include case insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the value of the attribute that the element must include

  • class_name (String) (defaults to: '*')

    the tag name to match

Returns:

  • (Array<Element>)

    the elements of type tag who’s attribute includes value



221
222
223
224
225
226
227
228
229
# File 'lib/appium_lib/ios/common/helper.rb', line 221

def find_eles_by_predicate_include(class_name: '*', value:)
  predicate = if class_name == '*'
                %(name contains[c] "#{value}" || label contains[c] "#{value}" || value contains[c] "#{value}")
              else
                %(type == "#{class_name}" && ) +
                  %((name contains[c] "#{value}" || label contains[c] "#{value}" || value contains[c] "#{value}"))
              end
  @driver.find_elements :predicate, predicate
end

#find_exact(value) ⇒ Element

Find the first element exactly matching value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Element)


34
35
36
# File 'lib/appium_lib/ios/element/generic.rb', line 34

def find_exact(value)
  ele_by_json_visible_exact '*', value
end

#finds(value) ⇒ Array<Element>

Find all elements containing value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Array<Element>)


27
28
29
# File 'lib/appium_lib/ios/element/generic.rb', line 27

def finds(value)
  eles_by_json_visible_contains '*', value
end

#finds_exact(value) ⇒ Array<Element>

Find all elements exactly matching value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Array<Element>)


41
42
43
# File 'lib/appium_lib/ios/element/generic.rb', line 41

def finds_exact(value)
  eles_by_json_visible_exact '*', value
end

#first_buttonUIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

Find the first UIAButton|XCUIElementTypeButton.



52
53
54
# File 'lib/appium_lib/ios/element/button.rb', line 52

def first_button
  first_ele button_class
end

#first_ele(class_name) ⇒ Element

Get the first tag that matches class_name

Parameters:

  • class_name (String)

    the tag to match

Returns:

  • (Element)


234
235
236
# File 'lib/appium_lib/ios/common/helper.rb', line 234

def first_ele(class_name)
  ele_index class_name, 1
end

#first_textUIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

Find the first UIAStaticText|XCUIElementTypeStaticText.



51
52
53
# File 'lib/appium_lib/ios/element/text.rb', line 51

def first_text
  first_ele static_text_class
end

#first_textfieldTextField

Find the first TextField.

Returns:

  • (TextField)


69
70
71
# File 'lib/appium_lib/ios/element/textfield.rb', line 69

def first_textfield
  ele_by_json _textfield_visible
end

#id(id) ⇒ Element

Find by id

Parameters:

  • id (String)

    the id to search for

Returns:

  • (Element)


101
102
103
# File 'lib/appium_lib/ios/common/helper.rb', line 101

def id(id)
  find_element(:id, id)
end

#ios_password(length = 1) ⇒ String

iOS only. On Android uiautomator always returns an empty string for EditText password.

Password character returned from value of UIASecureTextField

Parameters:

  • length (Integer) (defaults to: 1)

    the length of the password to generate

Returns:

  • (String)

    the returned string is of size length



58
59
60
# File 'lib/appium_lib/ios/common/helper.rb', line 58

def ios_password(length = 1)
  8226.chr('UTF-8') * length
end

#last_buttonUIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

TODO: add documentation regarding previous element.

Previous UIAElement is differ from UIAButton|XCUIElementTypeButton. So, the results are different.

Find the last UIAButton|XCUIElementTypeButton.



60
61
62
# File 'lib/appium_lib/ios/element/button.rb', line 60

def last_button
  last_ele button_class
end

#last_ele(class_name) ⇒ Element

Get the last tag that matches class_name

Parameters:

  • class_name (String)

    the tag to match

Returns:

  • (Element)


241
242
243
# File 'lib/appium_lib/ios/common/helper.rb', line 241

def last_ele(class_name)
  ele_index class_name, 'last()'
end

#last_textUIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

Find the last UIAStaticText|XCUIElementTypeStaticText.



57
58
59
# File 'lib/appium_lib/ios/element/text.rb', line 57

def last_text
  last_ele static_text_class
end

#last_textfieldTextField

Find the last TextField.

Returns:

  • (TextField)


75
76
77
78
79
80
# File 'lib/appium_lib/ios/element/textfield.rb', line 75

def last_textfield
  result = eles_by_json(_textfield_visible).last
  raise _no_such_element if result.nil?

  result
end

#page(opts = {}) ⇒ void

This method returns an undefined value.

Prints a string of interesting elements to the console.

Examples:

```ruby
page class: :UIAButton # filter on buttons
page class: :UIAButton, window: 1
```

Parameters:

  • visible (Hash)

    a customizable set of options

  • class (Hash)

    a customizable set of options



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/appium_lib/ios/common/helper.rb', line 74

def page(opts = {})
  class_name = opts.is_a?(Hash) ? opts.fetch(:class, nil) : opts

  source = get_source

  # current_context may be nil which breaks start_with
  if current_context&.start_with?('WEBVIEW')
    parser = @android_html_parser ||= Nokogiri::HTML::SAX::Parser.new(Appium::Common::HTMLElements.new)
    parser.document.reset
    parser.document.filter = class_name
    parser.parse source
    result = parser.document.result
    puts result
    result
  else
    parser = Nokogiri::XML::SAX::Parser.new(UITestElementsPrinter.new)
    if class_name
      parser.document.filter = class_name.is_a?(Symbol) ? class_name.to_s : class_name
    end
    parser.parse source
    nil
  end
end

#secure_text_field_classString

Returns Class name for secure text field.

Returns:

  • (String)

    Class name for secure text field



33
34
35
# File 'lib/appium_lib/ios/element/textfield.rb', line 33

def secure_text_field_class
  UIA_SECURE_TEXT_FIELD
end

#static_text_classString

Returns Class name for text.

Returns:

  • (String)

    Class name for text



25
26
27
# File 'lib/appium_lib/ios/element/text.rb', line 25

def static_text_class
  UIA_STATIC_TEXT
end

#string_attr_exact(class_name, attr, value) ⇒ Object



128
129
130
# File 'lib/appium_lib/ios/common/helper.rb', line 128

def string_attr_exact(class_name, attr, value)
  %(//#{class_name}[@visible="true" and @#{attr}="#{value}"])
end

#string_attr_include(class_name, attr, value) ⇒ Object



155
156
157
# File 'lib/appium_lib/ios/common/helper.rb', line 155

def string_attr_include(class_name, attr, value)
  %(//#{class_name}[@visible="true" and contains(translate(@#{attr},"#{value.upcase}", "#{value}"), "#{value}")])
end

#string_visible_contains(element, value) ⇒ String

Returns an object that matches the first element that contains value

example: ele_by_json_visible_contains ‘UIATextField’, ‘sign in’

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (String)


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/appium_lib/ios/common/helper.rb', line 299

def string_visible_contains(element, value)
  contains = {
    target: value,
    substring: true,
    insensitive: true
  }

  {
    typeArray: [element],
    onlyVisible: true,
    name: contains,
    label: contains,
    value: contains
  }
end

#string_visible_exact(element, value) ⇒ String

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

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (String)


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/appium_lib/ios/common/helper.rb', line 338

def string_visible_exact(element, value)
  exact = {
    target: value,
    substring: false,
    insensitive: false
  }

  {
    typeArray: [element],
    onlyVisible: true,
    name: exact,
    label: exact,
    value: exact
  }
end

#tag(class_name) ⇒ Element

Returns the first visible element matching class_name

Parameters:

  • class_name (String)

    the class_name to search for

Returns:

  • (Element)


249
250
251
# File 'lib/appium_lib/ios/common/helper.rb', line 249

def tag(class_name)
  ele_by_json(typeArray: [class_name], onlyVisible: true)
end

#tags(class_name) ⇒ Element

Returns all visible elements matching class_name

Parameters:

  • class_name (String)

    the class_name to search for

Returns:

  • (Element)


257
258
259
# File 'lib/appium_lib/ios/common/helper.rb', line 257

def tags(class_name)
  eles_by_json(typeArray: [class_name], onlyVisible: true)
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:

  • (Array[Element])


283
284
285
286
287
288
289
# File 'lib/appium_lib/ios/common/helper.rb', line 283

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

  class_names.flat_map do |class_name|
    value ? eles_by_json_visible_exact(class_name, value) : tags(class_name)
  end
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:

  • (Array[Element])


268
269
270
271
272
273
274
# File 'lib/appium_lib/ios/common/helper.rb', line 268

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

  class_names.flat_map do |class_name|
    value ? eles_by_json_visible_contains(class_name, value) : tags(class_name)
  end
end

#text(value) ⇒ UIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

Find the first UIAStaticText|XCUIElementTypeStaticText that contains value or by index. If int then the UIAStaticText|XCUIElementTypeStaticText at that index is returned.

Parameters:

  • value (String, Integer)

    the value to find.

Returns:



33
34
35
36
37
# File 'lib/appium_lib/ios/element/text.rb', line 33

def text(value)
  return ele_index static_text_class, value if value.is_a? Numeric

  ele_by_json_visible_contains static_text_class, value
end

#text_exact(value) ⇒ UIA_STATIC_TEXT|XCUIElementTypeStaticText

Find the first UIAStaticText|XCUIElementTypeStaticText that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



64
65
66
# File 'lib/appium_lib/ios/element/text.rb', line 64

def text_exact(value)
  ele_by_json_visible_exact static_text_class, value
end

#text_field_classString

Returns Class name for text field.

Returns:

  • (String)

    Class name for text field



28
29
30
# File 'lib/appium_lib/ios/element/textfield.rb', line 28

def text_field_class
  UIA_TEXT_FIELD
end

#textfield(value) ⇒ TextField

Find the first TextField that contains value or by index. Note: Uses XPath If int then the TextField at that index is returned.

Parameters:

  • value (String, Integer)

    the text to match exactly.

Returns:

  • (TextField)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/appium_lib/ios/element/textfield.rb', line 42

def textfield(value)
  if value.is_a? Numeric
    index = value
    raise ArgumentError, "#{index} is not a valid index. Must be >= 1" if index <= 0

    index -= 1 # eles_by_json and _textfields_with_predicate is 0 indexed.
    result = eles_by_json(_textfield_visible)[index]
    raise _no_such_element if result.nil?

    return result
  end

  ele_by_json _textfield_contains_string value
end

#textfield_exact(value) ⇒ TextField

Find the first TextField that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:

  • (TextField)


85
86
87
# File 'lib/appium_lib/ios/element/textfield.rb', line 85

def textfield_exact(value)
  ele_by_json _textfield_exact_string value
end

#textfields(value = false) ⇒ Array<TextField>

Find all TextFields containing value. If value is omitted, all TextFields are returned.

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:

  • (Array<TextField>)


61
62
63
64
65
# File 'lib/appium_lib/ios/element/textfield.rb', line 61

def textfields(value = false)
  return eles_by_json _textfield_visible unless value

  eles_by_json _textfield_contains_string value
end

#textfields_exact(value) ⇒ Array<TextField>

Find all TextFields that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:

  • (Array<TextField>)


92
93
94
# File 'lib/appium_lib/ios/element/textfield.rb', line 92

def textfields_exact(value)
  eles_by_json _textfield_exact_string value
end

#texts(value = false) ⇒ Array<UIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT>

Find all UIAStaticTexts|XCUIElementTypeStaticTexts containing value. If value is omitted, all UIAStaticTexts|XCUIElementTypeStaticTexts are returned

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:



43
44
45
46
47
# File 'lib/appium_lib/ios/element/text.rb', line 43

def texts(value = false)
  return tags static_text_class unless value

  eles_by_json_visible_contains static_text_class, value
end

#texts_exact(value) ⇒ Array<UIA_STATIC_TEXT|XCUIElementTypeStaticText>

Find all UIAStaticTexts|XCUIElementTypeStaticTexts that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



71
72
73
# File 'lib/appium_lib/ios/element/text.rb', line 71

def texts_exact(value)
  eles_by_json_visible_exact static_text_class, value
end