Error accessing UIDevice.shared.orientation

We're seeing an accessibility error at several points in our tests

Failed to get list of active applications: Accessibility error kAXErrorServerNotFound from AXUIElementCopyMultipleAttributeValues

This was working previously. We didn't do any significant iOS updates on the devices, so I'm not sure what could have changed.

One example is setting the device orientation:

UIDevice.shared.orientation = .portrait

When I break in the debugger at that point I also see the error when I try

po XCUIDevice.shared.orientation = .portrait.

If I try a second time then it works fine, but the first call always fails which causes the test to fail.

There are some other calls which behave similarly. First call always fails with the error above, second call is fine. They're not throwing an exception, so I can't handle it with a do/try/catch.

Is there an accessibility setting that needs to be made manually on the iOS device for this to work?

Are you testing on iOS 16 beta? This is mentioned as bug on iOS 16 beta. https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-16-release-notes

Although it mentioned is fixed on iOS 16 Beta 4, I still experience the same.

This discussion is similar as yours. https://developer.apple.com/forums/thread/707735

No, this was on a device running iOS 15. I haven't had any problems with iOS 16 so far.

Our problem isn't just orientation, and the failure message is consistent with every failure. The thing that seems oddest is that it will work fine the second call. In fact, if I break on the line of the call and make the same call in the debugger (and see it fail), then the call will succeed when I continue.

Error accessing UIDevice.shared.orientation
 
 
Q