xcode 你怎么能看到 XCUIElement 树?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32791752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can you see the XCUIElement tree?
提问by Joe Susnick
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 中的“page”命令?
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,但这只会为您提供该元素的信息。
回答by h.w.powers
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 automatically print out what the app sees right after you do something.
这样,如果您在查找某些内容时遇到问题,您可以让它在您执行某些操作后立即自动打印出应用程序看到的内容。
回答by Debo
This isn't exactly what you're asking for, but Xcode's Accessibility Inspectormakes 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 的Accessibility Inspector使您可以更轻松地查看视图层次结构,即哪些元素可通过标识符访问。(注意,重要的不是 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->Open Developer Tool->Accessibility Inspector。(您可能需要授予应用程序在“系统偏好设置”中运行的权限。)然后从 Xcode 启动您的 iOS 应用程序并将鼠标悬停在 SIMULATOR 中的任何 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,一旦我弄清楚如何使用 Accessibility Inspector 工具,问题就变得明显了。)
Thanks to the folks at shinobicontrols.com for the great tip!
感谢 shinobicontrols.com 上的人提供了很棒的提示!
回答by Nick McConnell
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 测试的角度来看,这可能不是一对一的,但它可能非常有帮助。希望有帮助。
回答by TinyTimZamboni
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.
Appium 这样做的方式是使用Facebook WebdriverAgent。据我所知,他们这样做的方式本质上是从根应用程序元素开始,收集有关每个子元素的信息,然后递归。
回答by Estev?o Lucas
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
使用idb ui describe-all
命令,您可以获得屏幕上所有元素(不是整个应用程序)的可访问性信息https://fbidb.io/docs/commands#accessibility-info