1
而iOS UITesting,我怎麼能兩個不同XCUIElement
區分?的iOS UITests - 如何區分兩個不同的XCUIElement?
比如我有兩個不同的UIButton
有相同的標籤串「按鈕」。如何檢查他們是不同的?做XCUIElement
提供身份證或任何不同的財產?
而iOS UITesting,我怎麼能兩個不同XCUIElement
區分?的iOS UITests - 如何區分兩個不同的XCUIElement?
比如我有兩個不同的UIButton
有相同的標籤串「按鈕」。如何檢查他們是不同的?做XCUIElement
提供身份證或任何不同的財產?
添加accessibilityIdentifier
在您的應用程序的代碼,每個按鈕,並通過其標識符訪問你的測試每個按鈕告訴他們分開。輔助標識符不是面向用戶,即使是輔助功能的用戶,所以這不會影響您的用戶體驗。
// app code
buttonA.accessibilityIdentifier = "buttonA"
buttonB.accessibilityIdentifier = "buttonB"
// test code
let app = XCUIApplication()
let buttonA = app.buttons["buttonA"]
let buttonB = app.buttons["buttonB"]