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
- UIAStaticText =
'UIAStaticText'.freeze
- XCUIElementTypeStaticText =
'XCUIElementTypeStaticText'.freeze
- UIAButton =
'UIAButton'.freeze
- XCUIElementTypeButton =
'XCUIElementTypeButton'.freeze
- UIATextField =
'UIATextField'.freeze
- UIASecureTextField =
'UIASecureTextField'.freeze
- XCUIElementTypeTextField =
'XCUIElementTypeTextField'.freeze
- XCUIElementTypeSecureTextField =
'XCUIElementTypeSecureTextField'.freeze
Instance Method Summary collapse
-
#_all_pred(opts) ⇒ Object
predicate - the predicate to evaluate on the main app.
-
#_by_json(opts) ⇒ Object
For Appium(automation name), not XCUITest typeArray - array of string types to search for.
- #_validate_object(*objects) ⇒ Object
-
#alert_accept ⇒ void
Accept the alert.
-
#alert_dismiss ⇒ void
Dismiss the alert.
-
#button(value) ⇒ UIAButton|XCUIElementTypeButton
Find the first UIAButton|XCUIElementTypeButton that contains value or by index.
-
#button_class ⇒ String
Class name for button.
-
#button_exact(value) ⇒ UIAButton|XCUIElementTypeButton
Find the first UIAButton|XCUIElementTypeButton that exactly matches value.
-
#buttons(value = false) ⇒ Array<UIAButton|XCUIElementTypeButton>
Find all UIAButtons|XCUIElementTypeButtons containing value.
-
#buttons_exact(value) ⇒ Array<UIAButton|XCUIElementTypeButton>
Find all UIAButtons|XCUIElementTypeButtons that exactly match value.
-
#ele_by_json(opts) ⇒ Object
see eles_by_json.
-
#ele_by_json_visible_contains(element, value) ⇒ Element
Find the first element that contains value.
-
#ele_by_json_visible_exact(element, value) ⇒ Element
Find the first element exactly matching value For Appium(automation name), not XCUITest.
-
#ele_index(class_name, index) ⇒ Element
Get the element of type class_name at matching index.
-
#ele_with_pred(opts) ⇒ Element
returns element matching predicate contained in the main app.
-
#eles_by_json(opts) ⇒ Object
For Appium(automation name), not XCUITest example usage:.
-
#eles_by_json_visible_contains(element, value) ⇒ Array<Element>
Find all elements containing value For Appium(automation name), not XCUITest.
-
#eles_by_json_visible_exact(element, value) ⇒ Element
Find all elements exactly matching value For Appium(automation name), not XCUITest.
-
#eles_with_pred(opts) ⇒ Array<Element>
returns elements matching predicate contained in the main app.
-
#find(value) ⇒ Element
Find the first element containing value.
-
#find_ele_by_attr(class_name, attr, value) ⇒ Element
Find the first element exactly matching class and attribute value.
-
#find_ele_by_attr_include(class_name, attr, value) ⇒ Element
Get the first tag by attribute that exactly matches value.
-
#find_ele_by_predicate(class_name: '*', value:) ⇒ Element
Find the first element exactly matching attribute case insensitive value.
-
#find_ele_by_predicate_include(class_name: '*', value:) ⇒ Element
Get the first elements that include insensitive value.
-
#find_eles_by_attr(class_name, attr, value) ⇒ Array<Element>
Find all elements exactly matching class and attribute value.
-
#find_eles_by_attr_include(class_name, attr, value) ⇒ Array<Element>
Get tags by attribute that include value.
-
#find_eles_by_predicate(class_name: '*', value:) ⇒ Array<Element>
Find all elements exactly matching attribute case insensitive value.
-
#find_eles_by_predicate_include(class_name: '*', value:) ⇒ Array<Element>
Get elements that include case insensitive value.
-
#find_exact(value) ⇒ Element
Find the first element exactly matching value.
-
#finds(value) ⇒ Array<Element>
Find all elements containing value.
-
#finds_exact(value) ⇒ Array<Element>
Find all elements exactly matching value.
-
#first_button ⇒ UIAButton|XCUIElementTypeButton
Find the first UIAButton|XCUIElementTypeButton.
-
#first_ele(class_name) ⇒ Element
Get the first tag that matches class_name.
-
#first_text ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the first UIAStaticText|XCUIElementTypeStaticText.
-
#first_textfield ⇒ TextField
Find the first TextField.
-
#id(id) ⇒ Element
Find by id.
-
#ios_password(length = 1) ⇒ String
iOS only.
-
#last_button ⇒ UIAButton|XCUIElementTypeButton
TODO: add documentation regarding previous element.
-
#last_ele(class_name) ⇒ Element
Get the last tag that matches class_name.
-
#last_text ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the last UIAStaticText|XCUIElementTypeStaticText.
-
#last_textfield ⇒ TextField
Find the last TextField.
-
#page(opts = {}) ⇒ void
Prints a string of interesting elements to the console.
-
#secure_text_field_class ⇒ String
Class name for secure text field.
-
#static_text_class ⇒ String
Class name for text.
- #string_attr_exact(class_name, attr, value) ⇒ Object
- #string_attr_include(class_name, attr, value) ⇒ Object
-
#string_visible_contains(element, value) ⇒ String
Returns an object that matches the first element that contains value.
-
#string_visible_exact(element, value) ⇒ String
Create an object to exactly match the first element with target value.
-
#tag(class_name) ⇒ Element
Returns the first visible element matching class_name.
-
#tags(class_name) ⇒ Element
Returns all visible elements matching class_name.
-
#tags_exact(class_names:, value: nil) ⇒ Array[Element]
Returns all visible elements matching class_names and value.
-
#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.
-
#text(value) ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the first UIAStaticText|XCUIElementTypeStaticText that contains value or by index.
-
#text_exact(value) ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the first UIAStaticText|XCUIElementTypeStaticText that exactly matches value.
-
#text_field_class ⇒ String
Class name for text field.
-
#textfield(value) ⇒ TextField
Find the first TextField that contains value or by index.
-
#textfield_exact(value) ⇒ TextField
Find the first TextField that exactly matches value.
-
#textfields(value = false) ⇒ Array<TextField>
Find all TextFields containing value.
-
#textfields_exact(value) ⇒ Array<TextField>
Find all TextFields that exactly match value.
-
#texts(value = false) ⇒ Array<UIAStaticText|XCUIElementTypeStaticText>
Find all UIAStaticTexts|XCUIElementTypeStaticTexts containing value.
-
#texts_exact(value) ⇒ Array<UIAStaticText|XCUIElementTypeStaticText>
Find all UIAStaticTexts|XCUIElementTypeStaticTexts that exactly match value.
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
362 363 364 365 366 367 368 |
# File 'lib/appium_lib/ios/common/helper.rb', line 362 def _all_pred(opts) predicate = opts[:predicate] raise '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,
}
}
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/appium_lib/ios/common/helper.rb', line 441 def _by_json(opts) valid_keys = i(typeArray onlyFirst onlyVisible name label value) unknown_keys = opts.keys - valid_keys raise "Unknown keys: #{unknown_keys}" unless unknown_keys.empty? type_array = opts[:typeArray] raise 'typeArray must be an array' unless type_array.is_a? Array only_first = opts[:onlyFirst] raise 'onlyFirst must be a boolean' unless [true, false].include? only_first only_visible = opts[:onlyVisible] raise '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 = " (function() {\n var opts = \#{opts.to_json};\n var result = false;\n\n try {\n result = $._elementOrElementsByType($.mainWindow(), opts);\n } catch (e) {\n }\n\n return result;\n })();\n JS\n\n res = execute_script element_or_elements_by_type\n res || raise(Appium::Ios::CommandError, 'mainWindow is nil')\nend\n" |
#_validate_object(*objects) ⇒ Object
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/appium_lib/ios/common/helper.rb', line 391 def _validate_object(*objects) raise '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 "Unknown keys: #{unknown_keys}" unless unknown_keys.empty? target = obj[:target] raise 'target must be a string' unless target.is_a? String substring = obj[:substring] raise 'substring must be a boolean' unless [true, false].include? substring insensitive = obj[:insensitive] raise 'insensitive must be a boolean' unless [true, false].include? insensitive end end |
#alert_accept ⇒ void
This method returns an undefined value.
Accept the alert.
5 6 7 8 9 |
# File 'lib/appium_lib/ios/element/alert.rb', line 5 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_dismiss ⇒ void
This method returns an undefined value.
Dismiss the alert.
13 14 15 16 17 |
# File 'lib/appium_lib/ios/element/alert.rb', line 13 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) ⇒ UIAButton|XCUIElementTypeButton
Find the first UIAButton|XCUIElementTypeButton that contains value or by index. If int then the UIAButton|XCUIElementTypeButton at that index is returned.
16 17 18 19 20 21 |
# File 'lib/appium_lib/ios/element/button.rb', line 16 def (value) # return button at index. return ele_index , value if value.is_a? Numeric ele_by_json_visible_contains , value end |
#button_class ⇒ String
Returns Class name for button.
8 9 10 |
# File 'lib/appium_lib/ios/element/button.rb', line 8 def UIAButton end |
#button_exact(value) ⇒ UIAButton|XCUIElementTypeButton
Find the first UIAButton|XCUIElementTypeButton that exactly matches value.
50 51 52 |
# File 'lib/appium_lib/ios/element/button.rb', line 50 def (value) ele_by_json_visible_exact , value end |
#buttons(value = false) ⇒ Array<UIAButton|XCUIElementTypeButton>
Find all UIAButtons|XCUIElementTypeButtons containing value. If value is omitted, all UIAButtons|XCUIElementTypeButtons are returned.
27 28 29 30 31 |
# File 'lib/appium_lib/ios/element/button.rb', line 27 def (value = false) return unless value eles_by_json_visible_contains , value end |
#buttons_exact(value) ⇒ Array<UIAButton|XCUIElementTypeButton>
Find all UIAButtons|XCUIElementTypeButtons that exactly match value.
57 58 59 |
# File 'lib/appium_lib/ios/element/button.rb', line 57 def (value) eles_by_json_visible_exact , value end |
#ele_by_json(opts) ⇒ Object
see eles_by_json
497 498 499 500 501 502 503 |
# File 'lib/appium_lib/ios/common/helper.rb', line 497 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
305 306 307 |
# File 'lib/appium_lib/ios/common/helper.rb', line 305 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
344 345 346 |
# File 'lib/appium_lib/ios/common/helper.rb', line 344 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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/appium_lib/ios/common/helper.rb', line 94 def ele_index(class_name, index) raise 'Index must be >= 1' unless index == 'last()' || (index.is_a?(Integer) && index >= 1) elements = (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
376 377 378 379 |
# File 'lib/appium_lib/ios/common/helper.rb', line 376 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,
},
})
491 492 493 494 |
# File 'lib/appium_lib/ios/common/helper.rb', line 491 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
314 315 316 |
# File 'lib/appium_lib/ios/common/helper.rb', line 314 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
353 354 355 |
# File 'lib/appium_lib/ios/common/helper.rb', line 353 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
387 388 389 |
# File 'lib/appium_lib/ios/common/helper.rb', line 387 def eles_with_pred(opts) find_elements(:uiautomation, _all_pred(opts)) end |
#find(value) ⇒ Element
Find the first element containing value
6 7 8 |
# File 'lib/appium_lib/ios/element/generic.rb', line 6 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.
124 125 126 |
# File 'lib/appium_lib/ios/common/helper.rb', line 124 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
176 177 178 |
# File 'lib/appium_lib/ios/common/helper.rb', line 176 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
148 149 150 151 152 153 |
# File 'lib/appium_lib/ios/common/helper.rb', line 148 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
194 195 196 197 198 199 |
# File 'lib/appium_lib/ios/common/helper.rb', line 194 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.
135 136 137 |
# File 'lib/appium_lib/ios/common/helper.rb', line 135 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
186 187 188 |
# File 'lib/appium_lib/ios/common/helper.rb', line 186 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
160 161 162 163 164 165 166 167 168 |
# File 'lib/appium_lib/ios/common/helper.rb', line 160 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
206 207 208 209 210 211 212 213 214 |
# File 'lib/appium_lib/ios/common/helper.rb', line 206 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
20 21 22 |
# File 'lib/appium_lib/ios/element/generic.rb', line 20 def find_exact(value) ele_by_json_visible_exact '*', value end |
#finds(value) ⇒ Array<Element>
Find all elements containing value
13 14 15 |
# File 'lib/appium_lib/ios/element/generic.rb', line 13 def finds(value) eles_by_json_visible_contains '*', value end |
#finds_exact(value) ⇒ Array<Element>
Find all elements exactly matching value
27 28 29 |
# File 'lib/appium_lib/ios/element/generic.rb', line 27 def finds_exact(value) eles_by_json_visible_exact '*', value end |
#first_button ⇒ UIAButton|XCUIElementTypeButton
Find the first UIAButton|XCUIElementTypeButton.
35 36 37 |
# File 'lib/appium_lib/ios/element/button.rb', line 35 def first_ele end |
#first_ele(class_name) ⇒ Element
Get the first tag that matches class_name
219 220 221 |
# File 'lib/appium_lib/ios/common/helper.rb', line 219 def first_ele(class_name) ele_index class_name, 1 end |
#first_text ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the first UIAStaticText|XCUIElementTypeStaticText.
34 35 36 |
# File 'lib/appium_lib/ios/element/text.rb', line 34 def first_text first_ele static_text_class end |
#first_textfield ⇒ TextField
Find the first TextField.
51 52 53 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 51 def first_textfield ele_by_json _textfield_visible end |
#id(id) ⇒ Element
Find by id
86 87 88 |
# File 'lib/appium_lib/ios/common/helper.rb', line 86 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
43 44 45 |
# File 'lib/appium_lib/ios/common/helper.rb', line 43 def ios_password(length = 1) 8226.chr('UTF-8') * length end |
#last_button ⇒ UIAButton|XCUIElementTypeButton
TODO: add documentation regarding previous element.
Previous UIAElement is differ from UIAButton|XCUIElementTypeButton. So, the results are different.
Find the last UIAButton|XCUIElementTypeButton.
43 44 45 |
# File 'lib/appium_lib/ios/element/button.rb', line 43 def last_ele end |
#last_ele(class_name) ⇒ Element
Get the last tag that matches class_name
226 227 228 |
# File 'lib/appium_lib/ios/common/helper.rb', line 226 def last_ele(class_name) ele_index class_name, 'last()' end |
#last_text ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the last UIAStaticText|XCUIElementTypeStaticText.
40 41 42 |
# File 'lib/appium_lib/ios/element/text.rb', line 40 def last_text last_ele static_text_class end |
#last_textfield ⇒ TextField
Find the last TextField.
57 58 59 60 61 62 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 57 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/appium_lib/ios/common/helper.rb', line 59 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 && 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_class ⇒ String
Returns Class name for secure text field.
15 16 17 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 15 def secure_text_field_class UIASecureTextField end |
#static_text_class ⇒ String
Returns Class name for text.
8 9 10 |
# File 'lib/appium_lib/ios/element/text.rb', line 8 def static_text_class UIAStaticText end |
#string_attr_exact(class_name, attr, value) ⇒ Object
113 114 115 |
# File 'lib/appium_lib/ios/common/helper.rb', line 113 def string_attr_exact(class_name, attr, value) %(//#{class_name}[@visible="true" and @#{attr}="#{value}"]) end |
#string_attr_include(class_name, attr, value) ⇒ Object
140 141 142 |
# File 'lib/appium_lib/ios/common/helper.rb', line 140 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’
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/appium_lib/ios/common/helper.rb', line 284 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
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/appium_lib/ios/common/helper.rb', line 323 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
234 235 236 |
# File 'lib/appium_lib/ios/common/helper.rb', line 234 def tag(class_name) ele_by_json(typeArray: [class_name], onlyVisible: true) end |
#tags(class_name) ⇒ Element
Returns all visible elements matching class_name
242 243 244 |
# File 'lib/appium_lib/ios/common/helper.rb', line 242 def (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.
268 269 270 271 272 273 274 |
# File 'lib/appium_lib/ios/common/helper.rb', line 268 def (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) : (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.
253 254 255 256 257 258 259 |
# File 'lib/appium_lib/ios/common/helper.rb', line 253 def (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) : (class_name) end end |
#text(value) ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the first UIAStaticText|XCUIElementTypeStaticText that contains value or by index. If int then the UIAStaticText|XCUIElementTypeStaticText at that index is returned.
16 17 18 19 20 |
# File 'lib/appium_lib/ios/element/text.rb', line 16 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) ⇒ UIAStaticText|XCUIElementTypeStaticText
Find the first UIAStaticText|XCUIElementTypeStaticText that exactly matches value.
47 48 49 |
# File 'lib/appium_lib/ios/element/text.rb', line 47 def text_exact(value) ele_by_json_visible_exact static_text_class, value end |
#text_field_class ⇒ String
Returns Class name for text field.
10 11 12 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 10 def text_field_class UIATextField 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 24 def textfield(value) if value.is_a? Numeric index = value raise "#{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.
67 68 69 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 67 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.
43 44 45 46 47 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 43 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.
74 75 76 |
# File 'lib/appium_lib/ios/element/textfield.rb', line 74 def textfields_exact(value) eles_by_json _textfield_exact_string value end |
#texts(value = false) ⇒ Array<UIAStaticText|XCUIElementTypeStaticText>
Find all UIAStaticTexts|XCUIElementTypeStaticTexts containing value. If value is omitted, all UIAStaticTexts|XCUIElementTypeStaticTexts are returned
26 27 28 29 30 |
# File 'lib/appium_lib/ios/element/text.rb', line 26 def texts(value = false) return static_text_class unless value eles_by_json_visible_contains static_text_class, value end |
#texts_exact(value) ⇒ Array<UIAStaticText|XCUIElementTypeStaticText>
Find all UIAStaticTexts|XCUIElementTypeStaticTexts that exactly match value.
54 55 56 |
# File 'lib/appium_lib/ios/element/text.rb', line 54 def texts_exact(value) eles_by_json_visible_exact static_text_class, value end |