简体   繁体   English

iOS UITests-XCUIElements标识符的作用是什么

[英]iOS UITests - What purpose XCUIElements identifier serves

While woking on iOS UITests, I found XCUIElement has a property, identifier , which was confronted from XCUIElementAttributes . 在iOS UITests上启动时,我发现XCUIElement具有一个属性identifier ,这是XCUIElementAttributes遇到的 When I debug, I found this is a real-only property and always contains empty string. 调试时,我发现这是一个只读属性,并且始终包含空字符串。 Can anyone explain what purpose this property serves? 谁能解释这个属性的目的是什么? I am unable to get any distinguishing property between two XCUIElement 我无法获得两个XCUIElement之间的任何区别属性

I cannot change the identifier, its immutable. 我无法更改标识符,它是不可变的。

在此处输入图片说明

The identifier property of an XCUIElement is the same as the accessibility identifier of the UIView it represents. XCUIElement的identifier属性与其表示的UIView的可访问性标识符相同。

// app code
let someButton: UIButton!
someButton.accessibilityIdentifier = "myIdentifer"

// test code
let button = XCUIApplication().buttons["myIdentifier"] // get XCUIElement for the button
print(button.identifier) // => "myIdentifier"

If the identifier is empty, this is because the accessibilityIdentifier property has not been set on the view. 如果identifier为空,这是因为尚未在视图上设置accessibilityIdentifier属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM