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?
Recording a UI TestFrom the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test. Whenever you interact with an element, Xcode writes the corresponding code for it into your method.
To run the XCUITests on XCode, you can click the highlighted icon below to see your newly created UI Test targets. You can hover on the “testExample()” test case and click the “Play” icon to run that specific test to see if everything was set up properly.
XCTest framework is one of those frameworks that enables its users to write basic unit, performance and some level of UI tests for iOS apps.
Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow. Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions aren't satisfied.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With