XCTest stuck and has error when take snapshot element on screen has much elements

Dear Apple Developer

[Background] We are developing a service running on test mode based on XCTest Framework to support streaming, remote and automation testing with iOS devices.

After we upgrade macOS Sonama and Xcode 15 version for upgrade XCTest for support iOS 17 around Jan-2024, we saw

We noticed that our running on test mode services stuck and hanging frequently after a period of time.

We have investigate and tried debug code and we found that main thread stuck and hanging when it call requesting snapshot of accessibility hierarchy for app. At the same time, we noticed that the application we were testing stuck and hanging too.

[Environment] Application testing: Tiktok MacOS: Sonoma 14.5 Xcode: Version 15.4 (15F31d) Device test: iPhone 12 (iOS 14.8.1)

Log detail:

    t =  1524.15s Wait for com.ss.iphone.ugc.Ame to idle
    t =  1536.54s Find the Application 'com.ss.iphone.ugc.Ame'
    t =  1536.54s     Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1597.56s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 1)
    t =  1597.56s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1658.58s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 2)
    t =  1658.58s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1718.58s     Collecting extra data to assist test failure triage
    t =  1718.58s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1778.59s         Requesting snapshot of accessibility hierarchy for app with pid 509
2024-08-19 14:16:44.990260+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0
2024-08-19 14:16:44.990428+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: XCTPerformOnMainRunLoop work timed out after 60.0s ((null)) (null) 0 0
    t =  1843.71s Find the Application 'com.ss.iphone.ugc.Ame'
    t =  1843.71s     Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1874.72s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 1)
    t =  1874.72s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1940.76s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 2)
    t =  1940.77s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2005.80s     Collecting extra data to assist test failure triage
    t =  2005.80s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2066.58s         Requesting snapshot of accessibility hierarchy for app with pid 509
2024-08-19 14:21:33.019582+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0
2024-08-19 14:21:33.019687+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: Unable to perform work on main run loop, process main thread busy for 30.0s ((null)) (null) 0 0
2024-08-19 14:21:33.020647+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0
2024-08-19 14:21:33.020722+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: No element snapshot found for Application 'com.ss.iphone.ugc.Ame'[0.00, 0.00] -> (200.0, 259.0) ((null)) (null) 0 0
2024-08-19 14:21:33.020801+0700 WebDriverAgentRunner-Runner[489:97809] *** Assertion failure in -[XCPointerEventPath initForTouchAtPoint:offset:], XCSynthesizedEventRecord.m:263
    t =  2291.08s Find the Application 'com.ss.iphone.ugc.Ame'
    t =  2291.08s     Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2352.10s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 1)
    t =  2352.10s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2413.11s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 2)
    t =  2413.11s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2473.12s     Collecting extra data to assist test failure triage
    t =  2473.12s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2533.13s         Requesting snapshot of accessibility hierarchy for app with pid 509
2024-08-19 14:29:19.552744+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0
2024-08-19 14:29:19.553054+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: XCTPerformOnMainRunLoop work timed out after 60.0s ((null)) (null) 0 0
    t =  2598.27s Find the Application 'com.ss.iphone.ugc.Ame'
    t =  2598.28s     Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2659.29s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 1)
    t =  2659.29s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2720.31s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 2)
    t =  2720.32s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2780.33s     Collecting extra data to assist test failure triage
    t =  2780.33s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  2840.34s         Requesting snapshot of accessibility hierarchy for app with pid 509
2024-08-19 14:34:26.806686+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0
2024-08-19 14:34:26.806828+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: XCTPerformOnMainRunLoop work timed out after 60.0s ((null)) (null) 0 0
2024-08-19 14:34:26.808114+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0
2024-08-19 14:34:26.808205+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: No element snapshot found for Application 'com.ss.iphone.ugc.Ame'[0.00, 0.00] -> (200.0, 259.0) ((null)) (null) 0 0
2024-08-19 14:34:26.809241+0700 WebDriverAgentRunner-Runner[489:97809] *** Assertion failure in -[XCPointerEventPath initForTouchAtPoint:offset:], XCSynthesizedEventRecord.m:263

It seems like fetching the snapshot of this app is taking quite a long time:

    t =  1597.56s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 1)
    t =  1597.56s         Requesting snapshot of accessibility hierarchy for app with pid 509
    t =  1658.58s     Find the Application 'com.ss.iphone.ugc.Ame' (retry 2)
    t =  1658.58s         Requesting snapshot of accessibility hierarchy for app with pid 509

Each request here is taking a full minute. To diagnose this further, we would need a result bundle from your test run.

We would be happy to look into this if you file Feedback using Feedback Assistant, and attach a result bundle from your failing test run.

XCTest stuck and has error when take snapshot element on screen has much elements
 
 
Q