How to test UIImageView elements in iOS XCTest?

≡放荡痞女 提交于 2019-11-30 04:15:18

问题


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).

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?


回答1:


Assert the presence of an image by its accessibility label.

Production Code

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

UI Test Code

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


来源:https://stackoverflow.com/questions/34342666/how-to-test-uiimageview-elements-in-ios-xctest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!