【问题标题】:XCUITest - Unable to find hit point for Image using iOS 11XCUITest - 无法使用 iOS 11 找到图像的命中点
【发布时间】:2018-01-16 22:59:39
【问题描述】:

由于 iOS 11 XCUITest 不再能够找到 UIImages 的命中点,这导致无法点击图像或使用press(forDuration:thenDragTo:) 将触摸拖动到它。

有一种解决方法可以点击有效的图像(在coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0)) 上使用tap)。同样的方法不适用于 thenDragTo 方法,因为它需要一个 XCUIElement。

有谁知道如何让 thenDragTo 方法工作(最好不必编辑生产代码)?

提前致谢

【问题讨论】:

    标签: ios image ios11 xcuitest


    【解决方案1】:

    它在我的 Xcode 9.2 测试中接受 XCUICoordinate

    extension XCUICoordinate {
        open func press(forDuration duration: TimeInterval, thenDragTo otherCoordinate: XCUICoordinate)
    }
    

    我可以这样使用它:

    let fromCoordinate = contentElement.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
    let toCoordinate = fromCoordinate.withOffset(CGVector(dx: 0, dy: 260))
    fromCoordinate.press(forDuration: 0.01, thenDragTo: toCoordinate)
    

    【讨论】:

    • 哦,当然。我在 XCUIElement 类型的对象上使用了press(_:thenDragTo:) 方法,然后它只提供拖动到另一个 XCUIElement(我猜这很有意义)。在 XCUICoordinate 上调用 press(_:thenDragTo) 我可以拖动到另一个坐标...谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 2017-12-07
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    相关资源
    最近更新 更多