XCode UITests 替代 .StaticText

XCode UITests alternative to .StaticText

有没有办法连接到 UI 元素的属性而不是静态文本?

当我录制 UI 测试时,我得到以下内容

sidemenuTable.cells.containingType(.StaticText, identifier:"MULTIMEDIA").childrenMatchingType(.StaticText).matchingIdentifier("MULTIMEDIA").elementBoundByIndex(0).tap()

问题是静态文本在目标之间发生变化,导致测试失败。我希望能够访问表视图中对象的属性。例如。如果自定义单元格的 属性 为 cellType

这样测试就独立于 UI 元素内的文本。

您可以在元素的 accessibilityIdentifier 上使用 textLabel 快捷方式。这不会呈现给用户,因此无论元素的内容如何,​​您都可以使其相同。

生产代码:

cell.accessibilityIdentifier = "My Cell"

测试代码:

let app = XCUIApplication()
app.staticTexts["My Cell"].tap()