Testing if an element is visible with Xcode 7 UITest

后端 未结 6 1388
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 10:19

I want to verify if an element is visible or not depending on its .hidden property but I don\'t find a valid way to do that using the new Xcode 7 UI test stuff.

6条回答
  •  没有蜡笔的小新
    2020-12-03 10:50

    My solution is to add accessibilityIdentifier dynamicly

    func someMethod() {
        label.isHidden = true
        label. accessibilityIdentifier = "isHidden"
    }
    
    func someOtherMethod {
        label.isHidden = false
        label. accessibilityIdentifier = "isVisible"
    }
    

    and the in UITest you can use it as

    if app.staticTexts["MyLabel"].identifier == "isHidden" {
        dosomething()
    }
    

提交回复
热议问题