简体   繁体   English

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

[英]iOS UITests - How to distinguish two different XCUIElement?

While iOS UITesting, how can I distinguish between two different XCUIElement ? 在进行iOS UITesting时,如何区分两个不同的XCUIElement

For example I have two different UIButton with same label string "Button". 例如,我有两个具有相同标签字符串“ Button”的不同UIButton How to check they are different? 如何检查它们是否不同? Do XCUIElement provides ID or any distinct property? XCUIElement是否提供ID或任何其他属性?

Add an accessibilityIdentifier to each button in your app's code and access each button by its identifier in your tests to tell them apart. 在应用程序代码中的每个按钮上添加一个accessibilityIdentifier ,并在测试中按其标识符访问每个按钮以区分它们。 Accessibility identifiers are not user-facing, even to Accessibility users, so this will not affect your user experience. 辅助功能标识符不是面向用户的,甚至不是面向用户的,因此这不会影响您的用户体验。

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

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

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

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