swift - XCUITest 等待未经测试的应用程序达到空闲状态
问题描述
- 我的用例执行过程中,点击跳转到第三方APP,比如AppStore或者浏览器
- 然后XCUITest一直在等待第三方APP达到idle状态
- 测试失败,因为找不到测试目标程序
为什么测试程序一直在等待第三方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```
解决方案
我在这个问题答案列表中找到了一个解决方案(第二个答案)[1]: Disabling waiting for idle state in UI testing of iOS apps
推荐阅读
- python - 解析方法的 Scrapy 参数
- excel - 无法从另一个工作簿复制选择
- php - 在自定义 php 文件中调用 WordPress 内置函数
- python - 绘制 CDF 的平滑曲线
- google-cloud-platform - 如何将图像存储在谷歌云中?
- php - Laravel 选择框,默认显示数据库值
- web-services - 方法 TRACE、HEAD、DELETE、CONNECT、OPTIONS、PUT 的安全 WS 端点
- mysql - mysql where子句中计算字段的使用
- mongodb - 使用带有 MongoTamplete 的 Spring Boot 2 测试与 MongoDb 的连接
- java - 存储在第三方服务的数据库 api 密钥中