Skip to content

Add class chain locator to XCUITest driver #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2017

Conversation

mykola-mokhnach
Copy link
Contributor

Add a new locator type for XCUITest-based driver. See facebookarchive/WebDriverAgent#442 for more details.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@imurchie
Copy link
Contributor

Can you write up a little bit about what this is and how to use it? We will also need an issue to track getting support into clients, or else it is not usable.

@mykola-mokhnach
Copy link
Contributor Author

@imurchie I can also create PRs for java_client (and, probably, for ruby and python clients as well). The only thing I don't like there is C# }:-)

@mykola-mokhnach
Copy link
Contributor Author

This description can also be found at https://github.com/facebook/WebDriverAgent/wiki/Queries

The class chain query type is similar to xpath, but can only include indexes and valid class names. Only search by direct children elements of the current element is supported. Examples of such requests:
XCUIElementTypeWindow/XCUIElementTypeButton[3] - select the third child button of the first child window element
XCUIElementTypeWindow - select all the children windows
XCUIElementTypeWindow[2] - select the second child window in the hierarchy. Indexing starts at 1
XCUIElementTypeWindow/XCUIElementTypeAny[3] - select the third child (of any type) of the first child window
XCUIElementTypeWindow[2]/XCUIElementTypeAny - select all the children of the second child window
XCUIElementTypeWindow[2]/XCUIElementTypeAny[-2] - select the second last child of the second child window
One may use '*' (star) character to substitute the universal 'XCUIElementTypeAny' class name

This query type has been added as a quick patch to speed up complicated xpath queries containing many levels of nested nodes and not containing xpath function calls or attributes comparison (such locators are not recommended at all, but people still use them though)

OR

to combine them with predicate search, since location by predicates does not respect nodes hierarchy. For example:

The xpath locator

//XCUIElementTypeTable/XCUIElementTypeCell[@value='bla']

might be times slower than
class chain

XCUIElementTypeWindow/*/*/XCUIElementTypeTable[2]

and then apply predicate search to the previous result:

type == 'XCUIElementTypeCell' AND value == 'bla'

@imurchie
Copy link
Contributor

Sounds good. Once we have client implementations we'll need to add real documentation on its usage somewhere.

@imurchie imurchie merged commit 325d38e into appium:master Mar 13, 2017
@mykola-mokhnach
Copy link
Contributor Author

@imurchie Just let me know where to add ;)

@imurchie
Copy link
Contributor

I'll have to think about it! But it is not necessary until we have ways of sending in the query.

@jlipps
Copy link
Member

jlipps commented Mar 15, 2017

great work on getting a faster xpath-like query into WDA, @mykola-mokhnach

@mykola-mokhnach
Copy link
Contributor Author

Thanks @jlipps. Also a nice piece of experience for me. It was literally implemented for the whole chain starting from WDA (ObjC) to Appium Server (NodeJS) and then Appium Java Client (java). There are also plans to do it for Python client when I have time and mood.

@jlipps
Copy link
Member

jlipps commented Mar 15, 2017

🎉 that's fantastic

@leeyc0704
Copy link

leeyc0704 commented Oct 23, 2020

//XCUIElementTypeTable/XCUIElementTypeCell/XCUIElementTypeStaticText[@name="XXX"]/parent::XCUIElementTypeCell/XCUIElementTypeStaticText
can ioschain implment like the above xpath? if can ,please give a exzample, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants