【问题标题】:How to test UIImageView elements in iOS XCTest?如何在 iOS XCTest 中测试 UIImageView 元素?
【发布时间】:2016-03-24 09:33:24
【问题描述】:

我正在尝试使用 XCTest UI 测试来测试我的 UI,并且在测试我的应用中的 UIImageViews 时遇到了麻烦(命中测试、存在等)。

在 XCUIElementType 的列表中没有这样的类型,当我查看超级视图的子视图时,我的 UIImageViews 出于某种原因没有在其中列出,尽管我可以在屏幕上和 Xcode 的 UI 检查器中看到它们。

有人遇到过这种问题吗?

【问题讨论】:

    标签: ios objective-c uiimageview xctest xcode-ui-testing


    【解决方案1】:

    通过其可访问性标签断言图像的存在。

    生产代码

    let image = UIImage(named: "profile")
    let imageView = UIImageView(image: image)
    imageView.accessibilityIdentifier = "Your profile image"
    

    界面测试代码

    let app = XCUIApplication()
    XCTAssert(app.images["Your profile image"].exists)
    

    【讨论】:

    • 如果imageView是动态cell原型的子视图呢?
    • 哦,实际上,我知道如何测试是否存在!很酷,点击它怎么样?我有手势识别器附加到 imageView?
    • 计算 XCUIElement* image = self.app.images[@"addToGroupButton1"]; [图像点击];谢谢!
    • 如何在单个 UIImageView 中检查多个图像更新(一个接一个)?
    • @Joe Masilotti 你知道如何检查图像本身而不是 imageView 是否存在吗?谢谢。
    猜你喜欢
    • 2014-02-13
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    • 2021-03-21
    • 2013-10-08
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多