Scroll until element is visible iOS UI Automation with xcode7

后端 未结 9 826
小鲜肉
小鲜肉 2021-01-30 10:39

So with the new xcode update apple has revamped the way we do UI testing. In instruments we used java script function \"isVisible\" to determine if our targeted element is visib

9条回答
  •  执笔经年
    2021-01-30 11:24

    Unfortunately .exists doesn't confirm that an element is currently visible - something like this still isn't perfect but it will provide more reliable validation working with table or collection view cells:

    extension XCUIElement {
        var displayed: Bool {
            guard self.exists && !CGRectIsEmpty(frame) else { return false }
            return CGRectContainsRect(XCUIApplication().windows.elementBoundByIndex(0).frame, frame)
        }
    }
    

    then you can write a simple loop like:

    func scrollDownUntilVisible(element: XCUIElement) {
        while !element.displayed {
            swipeDown()
        }
    }
    

提交回复
热议问题