如何像 appium 检查器一样检查 xcode ui 测试的元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38980209/
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 to inspect element for xcode ui test like appium inspector
提问by Eric Ipsum
I am doing xcode ui test forl an app. Previously i used
我正在为一个应用程序做 xcode ui 测试。以前我用过
appium
by which i can know the detail path of any element. Through its inspector, i can know the element name or xpath or anything.
通过它我可以知道任何元素的详细路径。通过它的检查器,我可以知道元素名称或 xpath 或任何东西。
But as per request, recently i switched to xcode ui test.
但根据要求,最近我切换到 xcode ui 测试。
I am facing issue in this new technology. I can't get the element details.
我在这项新技术中遇到了问题。我无法获取元素详细信息。
It gives details through record but this does not work all time.
它通过记录提供详细信息,但这并不总是有效。
Sometimes it's too much long.
有时太长了。
Is there any way to inspect the element like appium inspector so that
i can write my element path accordingly by myself without recording?
回答by itsViksIn
There are total 3 ways to do this:
共有 3 种方法可以做到这一点:
Accessibility Inspector from Simulator: Enable it on simulator by going to Settings->General->Accessibility->Accessibility Inspector. Then hover over an element to get the accessibility Label or Identifier.
Accessibility Inspector from Xcode developer tools: Right click on Xcode and open developer tool -> Accessibility Inspector.
debugDescription: It prints the elements of the view, you can use it in the console like:
XCUIApplication().debugDescription
模拟器中的辅助功能检查器:通过转到设置-> 常规-> 辅助功能-> 辅助功能检查器在模拟器上启用它。然后将鼠标悬停在元素上以获取可访问性标签或标识符。
Xcode 开发人员工具中的辅助功能检查器:右键单击 Xcode 并打开开发人员工具 -> 辅助功能检查器。
debugDescription:它打印视图的元素,您可以在控制台中使用它,例如:
XCUIApplication().debugDescription
or better:
或更好:
var string = XCUIApplication().debugDescription
string = Array(arrayLiteral: string).reduce("") {##代码## + ( == "" ? "\n" : )}
print(string)
Unlike Appium
XCTest
is more development centric, you will find it easy to work with if you set and own the accessibility of the application. You can set accessibilityIdentifier
to elements and consume the values in your tests.
不像Appium
XCTest
以开发为中心,如果您设置并拥有应用程序的可访问性,您会发现它很容易使用。您可以设置accessibilityIdentifier
为元素并在测试中使用这些值。