Testing UIAccessibility on iOS

Hey all,

I have a workflow that executes unit tests for my iOS app when a PR is opened. There are ~1k tests that get executed. I recently tried to introduce a test that tests the accessibilityElements of a UIView. These tests pass on my local machine, but do not pass on CircleCI. Interestingly, they failed locally using an iPod touch simulator, but passed with an iPhone 12 mini simulator.

Has anyone been able to get something like this to succeed? Maybe using techniques like: Testing UIKit accessibility in unit tests – Ole Begemann?

My test looks like this:

let label = AccessibleAttributedLabel(forAutoLayout: ())
...
let firstElement = label.accessibilityElements?.first as? UIAccessibilityElement
XCTAssertEqual(firstElement?.accessibilityLabel, "Read our Privacy Policy, link, and Terms of Use, link,.")

And I’m getting:

testAccessibilityElements, XCTAssertEqual failed: ("nil") is not equal to ("Optional("Read our Privacy Policy, link, and Terms of Use, link,.")")

Thanks!

-Nick