Xcode UI test - UI Testing Failure - Failed to scroll to visible (by AX action) when tap on Search field "Cancel' button

前端 未结 8 1499
时光取名叫无心
时光取名叫无心 2020-12-04 08:32

I am trying to dismiss the search field by tapping \'Cancel\' button in search bar.

The test case is failing to find the cancel button. It was working fine in Xcode

8条回答
  •  长情又很酷
    2020-12-04 08:56

    I guess here "Cancel" button returns false for hittable property, that is preventing it from tapping.

    If you see tap() in documentation it says

    /*!
     * Sends a tap event to a hittable point computed for the element.
     */
    - (void)tap;
    

    It seems things are broken with XCode 7.1.To keep myself (and u too ;)) unblocked from these issues I wrote a extension on XCUIElement that allows tap on element even if it is not hittable. Following can help you.

    /*Sends a tap event to a hittable/unhittable element.*/
    extension XCUIElement {
        func forceTapElement() {
            if self.hittable {
                self.tap()
            }
            else {
                let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
                coordinate.tap()
            }
        }
    }
    

    Now you can call as

    button.forceTapElement()
    

    Update - For swift 3 use following:

    extension XCUIElement {
        func forceTapElement() {
            if self.isHittable {
                self.tap()
            }
            else {
                let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx:0.0, dy:0.0))
                coordinate.tap()
            }
        }
    }
    

提交回复
热议问题