首页 > 解决方案 > XCUITest 等待未经测试的应用程序达到空闲状态

问题描述

  1. 我的用例执行过程中,点击跳转到第三方APP,比如AppStore或者浏览器
  2. 然后XCUITest一直在等待第三方APP达到idle状态
  3. 测试失败,因为找不到测试目标程序

为什么测试程序一直在等待第三方APP进入空闲状态,如何解决?

我尝试的解决方案:在测试用例中每次点击之前,都会检查目标APP的状态,如果不在前台,则将其拉回前台。但是这个方法并没有在上面的第二步中执行。

执行日志如下:

   t =  1871.85s Tap Application 'test app'[0.00, 0.00] -> (297.1, 160.2)
   t =  1871.85s     Wait for test app to idle
   t =  1872.03s     Find the Application 'test app'
   t =  1872.09s     Check for interrupting elements affecting "test app" Application
   t =  1872.18s         **Wait for com.apple.mobilesafari to idle**
   t =  1872.34s         **Wait for com.apple.springboard to idle**
   t =  1932.47s         Requesting snapshot of accessibility hierarchy for app with pid 58
   t =  1932.57s         Find: Descendants matching predicate identifier == "NotificationShortLookView" OR elementType == 7
   t =  1933.59s     Retrying `Tap Application 'test app'[0.00, 0.00] -> (297.1, 160.2)` (attempt #2)
   t =  1933.59s         Wait for test app to idle
   t =  1933.76s         Find the Application 'test app'
   t =  1964.77s             Find the Application 'test app' (retry 1)
   t =  1995.79s             Find the Application 'test app' (retry 2)
   t =  2025.80s             Collecting extra data to assist test failure triage
   t =  2025.81s                 Requesting snapshot of accessibility hierarchy for app with pid 1899
   t =  2025.82s                 Requesting snapshot of accessibility
hierarchy for app with pid 1899
/Users/zoro/Documents/workspace/zoro_swiftmonkey/zoro_swiftmonkeyUITests/zoro_swiftmonkeyUITests.swift:61: error: -[zoro_swiftmonkeyUITests.zoro_swiftmonkeyUITests testMonkey] : Failed to get matching snapshot: Timed out while evaluating UI query.
   t =  2030.37s Tear Down
Test Case '-[zoro_swiftmonkeyUITests.zoro_swiftmonkeyUITests testMonkey]' failed (2030.643 seconds).
Test Suite 'zoro_swiftmonkeyUITests' failed at 2021-03-05 11:25:32.133.
    Executed 1 test, with 1 failure (0 unexpected) in 2030.643 (2030.643) seconds
Test Suite 'zoro_swiftmonkeyUITests.xctest' failed at 2021-03-05 11:25:32.133.
    Executed 1 test, with 1 failure (0 unexpected) in 2030.643 (2030.644) seconds
Test Suite 'Selected tests' failed at 2021-03-05 11:25:32.134.
    Executed 1 test, with 1 failure (0 unexpected) in 2030.643 (2030.645) seconds```

标签: swiftxcuitestmonkey

解决方案


我在这个问题答案列表中找到了一个解决方案(第二个答案)[1]: Disabling waiting for idle state in UI testing of iOS apps


推荐阅读