Skip to content

Commit e0db50e

Browse files
authored
Add class chain (#515)
* add class chain * fix rubocop * add documentations
1 parent 43ea919 commit e0db50e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

docs/ios_xcuitest.md

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ textfield(value) # Return a XCUIElementTypeSecureTextField or XCUIElementTypeTex
5353
finds_exact(value) # Return any elements include `value` as its name attributes.
5454
```
5555

56+
### with Class Chain
57+
- require Appium 1.6.4+
58+
- https://github.com/appium/appium-xcuitest-driver/pull/391
59+
- https://github.com/appium/java-client/pull/599/files
60+
- WebDriverAgent
61+
- https://github.com/facebook/WebDriverAgent/wiki/Queries
62+
5663
### with XPath
5764
- It is better to avoid XPath strategy.
5865
- https://github.com/appium/appium/blob/v1.6.2/docs/en/advanced-concepts/migrating-to-xcuitest.md#xpath-locator-strategy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# rake ios[ios/mobile_methods]
2+
describe 'ios/mobile_methods' do
3+
def before_first
4+
screen.must_equal catalog
5+
end
6+
7+
t 'an element with class chain' do
8+
element = find_element :class_chain, 'XCUIElementTypeWindow/*/*/XCUIElementTypeStaticText'
9+
10+
element.name.must_equal catalog
11+
end
12+
13+
t 'elements with class chain' do
14+
elements = find_elements :class_chain, 'XCUIElementTypeWindow/*/*'
15+
16+
elements.size.must_equal 2
17+
elements[0].name.must_equal catalog
18+
elements[1].name.must_be_nil
19+
end
20+
end

lib/appium_lib/ios/mobile_methods.rb

+14
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ class << self
1616
# find_elements :predicate, 'wdName == "Buttons"'
1717
# find_elements :predicate, 'wdValue == "SearchBar" AND isWDDivisible == 1'
1818
# ```
19+
#
20+
# @!method ios_class_chain_find
21+
# Only for XCUITest(WebDriverAgent)
22+
# find_element/s can be used with a [class chain]( https://github.com/facebook/WebDriverAgent/wiki/Queries)
23+
#
24+
# ```ruby
25+
# # select the third child button of the first child window element
26+
# find_elements :class_chain, 'XCUIElementTypeWindow/XCUIElementTypeButton[3]'
27+
# # select all the children windows
28+
# find_elements :class_chain, 'XCUIElementTypeWindow'
29+
# # select the second last child of the second child window
30+
# find_elements :class_chain, 'XCUIElementTypeWindow[2]/XCUIElementTypeAny[-2]'
31+
# ```
1932
def extended(_mod)
2033
::Appium::Driver::SearchContext::FINDERS[:uiautomation] = '-ios uiautomation'
2134
::Appium::Driver::SearchContext::FINDERS[:predicate] = '-ios predicate string'
35+
::Appium::Driver::SearchContext::FINDERS[:class_chain] = '-ios class chain'
2236
end
2337
end # class << self
2438
end # module Ios

0 commit comments

Comments
 (0)