How to test UIImageView elements in iOS XCTest?(如何在 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 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS XCTest 中测试 UIImageView 元素?
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
