Skip to content

Commit c09cf1e

Browse files
authored
add tags_include and tags_exact to find value (#490)
* add tags_include and tags_exact to find value * add tests and fix typo * add comments for performance * arrange documents a bit * fix lint
1 parent 39fd66f commit c09cf1e

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

ios_tests/lib/ios/specs/ios/helper.rb

+17
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,21 @@ def before_first
3030
t 'ios_version' do
3131
ios_version.wont_be_empty
3232
end
33+
34+
t 'tags_include' do
35+
elements = tags_include class_names: %w(XCUIElementTypeTextView XCUIElementTypeStaticText)
36+
elements.length.must_be 24
37+
38+
elements = tags_include class_names: %w(XCUIElementTypeTextView XCUIElementTypeStaticText), value: 'u'
39+
elements.length.must_be 13
40+
end
41+
42+
t 'tags_include' do
43+
elements = tags_exact class_names: %w(XCUIElementTypeTextView XCUIElementTypeStaticText)
44+
elements.length.must_be 24
45+
46+
elements = tags_exact class_names: %w(XCUIElementTypeTextView XCUIElementTypeStaticText), value: 'Buttons'
47+
elements.length.must_be 1
48+
elements.first.value.must_equal 'Buttons'
49+
end
3350
end

lib/appium_lib/ios/helper.rb

+40
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,46 @@ def tags(class_name)
338338
end
339339
end
340340

341+
# Returns all visible elements matching class_names and value
342+
# This method calls find_element/s and element.value/text many times.
343+
# So, if you set many class_names, this method's performance become worse.
344+
#
345+
# @param class_names [Array[String]] the class_names to search for
346+
# @param value [String] the value to search for
347+
# @return [Array[Element]]
348+
def tags_include(class_names:, value: nil)
349+
return unless class_names.is_a? Array
350+
351+
class_names.flat_map do |class_name|
352+
if automation_name_is_xcuitest?
353+
visible_elements = tags(class_name)
354+
value ? elements_include(visible_elements, value) : visible_elements
355+
else
356+
value ? eles_by_json_visible_contains(class_name, value) : tags(class_name)
357+
end
358+
end
359+
end
360+
361+
# Returns all visible elements matching class_names and value.
362+
# This method calls find_element/s and element.value/text many times.
363+
# So, if you set many class_names, this method's performance become worse.
364+
#
365+
# @param class_names [Array[String]] the class_names to search for
366+
# @param value [String] the value to search for
367+
# @return [Array[Element]]
368+
def tags_exact(class_names:, value: nil)
369+
return unless class_names.is_a? Array
370+
371+
class_names.flat_map do |class_name|
372+
if automation_name_is_xcuitest?
373+
visible_elements = tags(class_name)
374+
value ? elements_exact(visible_elements, value) : visible_elements
375+
else
376+
value ? eles_by_json_visible_exact(class_name, value) : tags(class_name)
377+
end
378+
end
379+
end
380+
341381
# @private
342382
# Returns an object that matches the first element that contains value
343383
#

0 commit comments

Comments
 (0)