In UI/Automation Testing using Xcode 7, is there a way to list all of the XCUIElements on an app screen? Like in a tree or list, or even something in the Xcode UI? I can record tests for the app under test using clicks, but when I go to run the test, it fails. It fails because it can't find the XCUIElements from the generated code.
2 Answers
You can view it in Xcode hierarchy debugger.
From Apple Docs:
To enter the view debugger, run your app in Xcode and click the Debug View Hierarchy button in the debug bar.

- 1,105
- 1
- 11
- 30
You can debug the state of UI element using,
XCUIElement.debugDescription
It returns a snapshot of UIView in html format with a nice look up into the UI elements state with properties like element type(e.g textField, button), traits like focussed, enabled and values e.g placeholderValue.
You can also use accessibilityInspector app to look into accessibility attributes for the UI Elements on the view and verify that elements have accessibility properties set correctly.
Another handy tool to investigate the view is new hierarchy viewer which can be invoked during recording from debug console toolbar or Debug Navigator filter when you enable breakpoint in your test code.
Xcode 7 also has a nice test reporting under Report Navigator which can help you drill down exact reason with the test failure. e.g
UI Test Activity:
Assertion Failure: Asynchronous wait failed: Exceeded timeout of 10 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Logout" Button".
Hope this helps.

- 440
- 3
- 8
-
I already knew about debugDescription; it does what I need, but isn't very easy to read. Thanks for the other stuff though. – ajc6432 Oct 06 '15 at 18:44
-
I'd love to see an example of how to use debugDescription. I've never seen it provide anything in html format. – Don Simon Nov 11 '15 at 20:13