Search code examples
objective-cswiftxctest

Parents and siblings in query in XCTest (UI testing)


In other languages is possible to make such query:

class:B text:"text_I_looking_for" sibling class:C

or

class:B text:"text_I_looking_for" parent class:A child class:C

How to perform such query in XCTest? I need find element to 1. Check if it's present 2. Click it.

PS I know XCTest has simply syntax, but in some cases it's not enough solution. Maybe it's possible to use NSPredicate syntax?


Solution

  • Today I find out Xcode 7.3 is using this mechanism:

    XCUIApplication().otherElements.containingType(.Image, identifier:"circle").staticTexts["3"]
    

    This query will return staticText object with "3" as value. This object has 'otherElement' as a parent and 'Image' with id 'circle' as sibling.