How to test UIImageView elements in iOS XCTest?
Asked Answered
Q

1

9

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?

Quandary answered 17/12, 2015 at 19:26 Comment(0)
E
18

Assert the presence of an image by its accessibility label.

Production Code

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

UI Test Code

let app = XCUIApplication()
XCTAssert(app.images["Your profile image"].exists)
Excited answered 17/12, 2015 at 23:20 Comment(6)
what if the imageView is a subview of the dynamic cell prototype ?Quandary
oh actually, I see how I can test for existence! Cool, what about tapping on it? I have the gesture recognizer attached to the imageView?Quandary
figured XCUIElement* image = self.app.images[@"addToGroupButton1"]; [image tap]; thank you!Quandary
How to check for multiple image updates(one after another) in a single UIImageView?Dorsad
@Joe Masilotti Do you know how to check whether the image itself, instead of the imageView, does exist? thx.Resignation
Swift 4. XCTAssert(app.images["Your profile image"].exists)Incline

© 2022 - 2024 — McMap. All rights reserved.