如何在 iOS XCTest 中测试 UIImageView 元素? [英] How to test UIImageView elements in iOS XCTest?

查看:24
本文介绍了如何在 iOS XCTest 中测试 UIImageView 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to test my UIs using XCTest UI testing, and having troubles of testing UIImageViewsI have in my app (hit tests, presence etc).

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

In the list of the XCUIElementType there is no such type, and when I look at the children of the superview my UIImageViews are not listed there for some reason eventhough I can see them on screen and in the UI inspector in the Xcode.

有人遇到过这种问题吗?

Has anyone had this kind of problem?

推荐答案

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

Assert the presence of an image by its accessibility label.

生产代码

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)

这篇关于如何在 iOS XCTest 中测试 UIImageView 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆