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

查看:103
本文介绍了如何在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.accessibilityLabel = "Your profile image"

UI测试代码

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

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

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