Mac UI Tests Failing to Detect Out-of-Hierarchy Elements

Overview

macOS test application is unable to detect elements beyond a certain length during UI testing after an Xcode(14/15) update.

Issue Description

We have a test app for both iOS and macOS, sharing the same code except for different UI implementations. During UI tests, the app opens a webpage in WKWebView. This is a long webpage with multiple sections, approximately 200 for the sake of clarity. The app screen can show 4 elements at a time. Our UI tests navigate to each section and perform various tasks.

Since upgrading from Xcode 13 to 15, we've encountered an issue specifically on macOS (unsure if it's related to Swift or Xcode). Our Mac UI test i.e. XCUIApplication() is unable to find elements beyond a certain length, which appear to be out of the view hierarchy. When we use app.debugDescription, it only returns 180 sections, missing the last 20. The HTML code of the webpage is consistent, with all sections structured similarly.

Troubleshooting Steps

  1. Accessibility Inspector: Using Xcode’s Accessibility Inspector yields the same result, detecting only 180 sections.
  2. Manual Scrolling: We tried manually scrolling to the missing sections. Although we can see these sections on the screen, app.debugDescription still only reports 180 sections, causing the UI test to fail in recognizing the last 20 sections.
  3. Deleting Sections: If we delete the top 20 sections of the webpage, it can then find the 200th element. This suggests we might be hitting some limit or restriction we are not aware of. However, on iOS, the same webpage returns all 200 sections without issue.

Additional Information

This issue is causing a problem only on the Mac app. In our Cocoa Mac application, we are using NSTabView, if that information helps with the investigation. We are wondering if there are any settings or flags we might have missed?

Request for Assistance

Any help would be greatly appreciated, as this issue is currently blocking us and it was working fine in the previous version.

Question

Is there any way we can bring those 20 elements into the hierarchy?

Accessibility has changed their implementation in to speed up the process of reading UI hierarchies over the past several releases. I am not sure what the specific limits are, but there were additional limits added to speed up this process. If you perform a press-and-hold action on your XCUIApplication, swiping down the page in a loop, the last 20 elements should eventually load into the Accessibility hierarchy.

Recommended API: https://developer.apple.com/documentation/xctest/xcuicoordinate/3551692-press

Mac UI Tests Failing to Detect Out-of-Hierarchy Elements
 
 
Q