In my UI tests, I create a UIView
programmatically using (shortened)
let topMarker = UIView.init(frame: CGRect.init())
…
topMarker.accessibilityIdentifier = kTopMarker
The topMarker
view is in a custom table view cell.
In my UI tests, I use
let new1stCell = app.cells.element(boundBy: 0)
let topMarker = new1stCell.otherElements[kTopMarker]
let topMarkerExists = topMarker.waitForExistence(timeout: 15)
XCTAssertTrue(topMarkerExists, "Top marker does not exist")
XCTAssertTrue(topMarker.isHittable, "Top marker is not hittable")
When I set a Test Failure breakpoint, the test stops at the last line, i.e. topMarker
exists, but is not hittable.
On the other hand, I can see the view in the snapshot, i.e. it exists and is visible.
This is stange, because the docs say:
isHittable returns true if the element exists and can be clicked, tapped, or pressed at its current location. It returns false if the element does not exist, is offscreen, or is covered by another element.
I thought, maybe it is visible, but cannot be clicked, tapped, or pressed, because userInteractionEnable
is not true
, but even if I set this property to true
, the view does not become hittable.
What am I missing?
Problem solved:
An XCUIElement is only hittable, if its isAccessibilityElement
property is set to true.
The docs to property isAccessibilityElement
say
The default value for this property is false unless the receiver is a standard UIKit control, in which case the value is true.
Assistive applications can get information only about objects that are represented by accessibility elements. Therefore, if you implement a custom control or view that should be accessible to users with disabilities, set this property to true.
My UIView
that I instantiated programmatically is not a standard UIKit control. As soon as I added
topMarker.isAccessibilityElement = true
the test
XCTAssertTrue(topMarker.isHittable, "Top marker is not hittable")
succeeded.
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