24

Background:

I'm experimenting with ui level testing in iOS 9.0 with XCode GM.

Question:

Is there a command in XCode GM that will allow you to see a 'tree' of accessible elements and their relationships? Something similar to the 'page' command in Appium?

Ideally I would be able to run a command in the debugger that would give me a list of elements available for selection/manipulation. Currently you can use debugDescription on a single XCUIElement but that only gives you info for that element.

Senseful
  • 86,719
  • 67
  • 308
  • 465
Joe Susnick
  • 6,544
  • 5
  • 44
  • 50

6 Answers6

40

Set a break point where you would like to see the tree... in the debugger type:

po print(XCUIApplication().debugDescription)

That prints out everything XCUITesting has access to. You can also just throw that in to your test:

func testTreeExample() {
  XCUIApplication().buttons["login"].tap()
  print(XCUIApplication().debugDescription)
  XCUIApplication().buttons["next"].tap()
  print(XCUIApplication().debugDescription)
}

Thta way if you are having trouble finding something you can have it automatically print out what the app sees right after you do something.

h.w.powers
  • 820
  • 8
  • 10
  • 1
    The problem with debugDescription is that it does't format the output properly and is very hard to read.`po XCUIApplication()` will print the hierarchy out in a nice tree format – kakubei Nov 23 '21 at 17:13
12

This isn't exactly what you're asking for, but Xcode’s Accessibility Inspector makes it much easier to look at your view hierarchy in terms of what elements are accessible via Identifiers. (N.B. It's not the "Label" in IB's Accessibility panel that matters, it's the "Identifier" field.):

In Xcode 7.2, open Xcode->Open Developer Tool->Accessibility Inspector. (You may need to give the app permission to run in System Preferences.) Then launch your iOS app from Xcode and hover over any UI element in the SIMULATOR. You’ll see comprehensive information about the element type, description, hierarchy, etc.

Anytime you record UI actions and the output doesn't look right, use the tool to figure out what accessibility descriptions need to be added, changed, or removed. (I spent a couple days trying to get a deeply embedded UISegmentedControl to change via the UI Test harness, and the problem became obvious once I figured out how to use the Accessibility Inspector tool.)

Thanks to the folks at shinobicontrols.com for the great tip!

Debo
  • 308
  • 2
  • 7
  • 1
    I'm not fully on board with ease of use of Accessibility Inspector. I've found it to be very flakey and it provides incomplete information. – Adrian Nov 13 '19 at 22:41
3

I would suggest choosing from the menu bar: Debug > View Debugging > Capture View Hierarchy when running in debug. Not only do you a way of visually representing the views but also the left-side debug navigator shows the hierarchy. This may not be one-for-one with UI Testing's perspective but it can be very helpful. Hope that helps.

Nick McConnell
  • 821
  • 8
  • 28
  • 3
    That's really cool, but it doesn't answer in terms of accessibility... It would be nice if apple gave us a convenience method to get a list of available elements with identifiers. – Joe Susnick Sep 30 '15 at 14:54
  • When you select a view in Xcode's view debugger, the object inspector on the right shows accessibility information. That might be useful. – wolfrevo Jun 23 '16 at 10:25
0

The way Appium does this is using Facebook WebdriverAgent. As far as I can tell, the way they do it, essentially, is starting from the root application element and collecting information about each child, then recursing.

TinyTimZamboni
  • 5,275
  • 3
  • 28
  • 24
  • 1
    mind answering this question if you know the answer? https://stackoverflow.com/questions/58391393/how-does-a-ui-app-inspectors-like-the-one-in-appium-work – Just a coder Oct 27 '19 at 23:03
0

What about http://fbidb.io?

With idb ui describe-all command you get the accessibility information of all the elements on screen (not the entire app) https://fbidb.io/docs/commands#accessibility-info

Estevão Lucas
  • 4,440
  • 34
  • 37
0

Put a breakpoint in any of your tests then just do: po XCUIApplication() and that will print out the whole app's accessibility hierarchy in easy to read tree format.

kakubei
  • 5,321
  • 4
  • 44
  • 66