Background:
背景:
I'm experimenting with ui level testing in iOS 9.0 with XCode GM.
我正在用XCode GM测试iOS 9.0中的ui级别。
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?
XCode GM中是否有一个命令可以让您看到可访问元素及其关系的“树”?类似于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.
理想情况下,我可以在调试器中运行一个命令,该命令将为我提供可供选择/操作的元素列表。目前,您可以在单个XCUIElement上使用debugDescription,但这只提供该元素的信息。
3 个解决方案
#1
7
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.):
这并不是您所要求的,但是Xcode的可访问性检查器使查看视图层次结构更容易,因为通过标识符可以访问哪些元素。(注意:重要的不是IB可访问性面板中的“标签”,而是“标识符”字段。)
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.
在Xcode 7.2中,打开Xcode->打开开发人员工具->可访问性检查器。(你可能需要给应用许可才能在系统首选项中运行。)然后从Xcode中启动您的iOS应用程序,并将鼠标悬停在模拟器中的任何UI元素上。您将看到有关元素类型、描述、层次结构等的全面信息。
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.)
当您记录UI动作并且输出看起来不正确时,请使用该工具来确定需要添加、更改或删除哪些可访问性描述。(我花了几天的时间试图通过UI测试工具来实现一个深度嵌入的UISegmentedControl,并且一旦我知道如何使用可访问性检查工具,问题就变得显而易见了。)
Thanks to the folks at shinobicontrols.com for the great tip!
感谢shinobicontrols.com网站上的朋友们,为你提供了很棒的建议!
#2
4
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.
我建议从菜单栏中选择:调试>视图调试>捕获视图层次结构,在调试中运行。不仅可以直观地表示视图,还可以使用左侧的调试导航器显示层次结构。从UI测试的角度来看,这可能不是一对一的,但它可能非常有用。希望有帮助。
#3
4
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:
它打印出XCUITesting可以访问的所有内容。你也可以把它加入到你的测试中:
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 autmatically print out what the app sees right after you do something.
如果你找不到什么东西,你可以让它自动打印出你做了什么之后应用看到的东西。
#1
7
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.):
这并不是您所要求的,但是Xcode的可访问性检查器使查看视图层次结构更容易,因为通过标识符可以访问哪些元素。(注意:重要的不是IB可访问性面板中的“标签”,而是“标识符”字段。)
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.
在Xcode 7.2中,打开Xcode->打开开发人员工具->可访问性检查器。(你可能需要给应用许可才能在系统首选项中运行。)然后从Xcode中启动您的iOS应用程序,并将鼠标悬停在模拟器中的任何UI元素上。您将看到有关元素类型、描述、层次结构等的全面信息。
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.)
当您记录UI动作并且输出看起来不正确时,请使用该工具来确定需要添加、更改或删除哪些可访问性描述。(我花了几天的时间试图通过UI测试工具来实现一个深度嵌入的UISegmentedControl,并且一旦我知道如何使用可访问性检查工具,问题就变得显而易见了。)
Thanks to the folks at shinobicontrols.com for the great tip!
感谢shinobicontrols.com网站上的朋友们,为你提供了很棒的建议!
#2
4
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.
我建议从菜单栏中选择:调试>视图调试>捕获视图层次结构,在调试中运行。不仅可以直观地表示视图,还可以使用左侧的调试导航器显示层次结构。从UI测试的角度来看,这可能不是一对一的,但它可能非常有用。希望有帮助。
#3
4
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:
它打印出XCUITesting可以访问的所有内容。你也可以把它加入到你的测试中:
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 autmatically print out what the app sees right after you do something.
如果你找不到什么东西,你可以让它自动打印出你做了什么之后应用看到的东西。