gpt4 book ai didi

iOS UITests - 如何区分两个不同的 XCUIElement?

转载 作者:行者123 更新时间:2023-11-28 20:28:20 26 4
gpt4 key购买 nike

iOS UITesting时,如何区分两个不同的XCUIElement

例如,我有两个不同的 UIButton 具有相同的标签字符串“Button”。如何检查它们是否不同? XCUIElement 是否提供 ID 或任何不同的属性?

最佳答案

accessibilityIdentifier 添加到应用程序代码中的每个按钮,并在测试中通过其标识符访问每个按钮以区分它们。辅助功能标识符不面向用户,即使是辅助功能用户也是如此,因此这不会影响您的用户体验。

// app code
buttonA.accessibilityIdentifier = "buttonA"
buttonB.accessibilityIdentifier = "buttonB"

// test code
let app = XCUIApplication()
let buttonA = app.buttons["buttonA"]
let buttonB = app.buttons["buttonB"]

关于iOS UITests - 如何区分两个不同的 XCUIElement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42507859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com