如何在 iOS XCTest 中测试 UIImageView 元素?

How to test UIImageView elements in iOS XCTest?

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

在 XCUIElementType 的列表中没有这样的类型,当我查看超级视图的子视图时,由于某种原因我的 UIImageViews 没有列出,尽管我可以在屏幕上和 Xcode.

中的 UI 检查器中查看它们

有人遇到过这种问题吗?

通过无障碍标签声明图像的存在。

生产代码

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

UI 测试代码

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