ios - XCTestCase:无法在导航栏中按下自定义栏按钮
问题描述
我正在为 iOS 应用程序编写测试,但无法单击自定义栏按钮。它是一个带有 UIImageView 的条形按钮。图像有一个accessibilityIdentifier = "settingsBarImage"
,条形按钮有一个accessibilityIdentifier = "settingsBarButton"
当我打印带有print(app.debugDescription)
按钮的小部件树时,它存在并且是可点击的。
NavigationBar, 0x60000320b480, {{0.0, 44.0}, {375.0, 44.0}}, identifier: 'Overview'
Button, 0x60000320b560, {{16.0, 51.0}, {30.0, 30.0}}, identifier: 'settingsBarButton', label: 'Your profile picture.'
StaticText, 0x60000320b640, {{150.0, 55.7}, {75.0, 20.3}}, label: 'Overview'
我试过了:
app.navigationBars.button.firstMatch.tap()
app.navigationBars["Overview"].buttons["settingsBarButton"].tap()
app.buttons["settingsBarButton"].tap()
app.otherElement["settingsBarButton"].tap()
及其每一种组合。
结果总是一样的:
t = 14.74s Tap Button
t = 14.74s Wait for com.sap.mobile.apps.ProjectCompanion to idle
t = 14.77s Find the Button
t = 15.82s Find the Button (retry 1)
t = 16.87s Find the Button (retry 2)
t = 16.92s Collecting extra data to assist test failure triage
t = 16.92s Requesting snapshot of accessibility hierarchy for app with pid 89909
t = 16.95s Requesting snapshot of accessibility hierarchy for app with pid 89909
t = 17.06s Assertion Failure: OverviewScreenBase.swift:31: Failed to get matching snapshot: No matches found for first query match sequence: `Descendants matching type NavigationBar` -> `Descendants matching type Button`, given input App element pid: 89909 (no attribute values faulted in)
Possibly caused by runtime issues:
如果有人遇到过这个问题,我将不胜感激。
最好的问候,鸡
编辑:经过更多的实验,我有更多的信息。正常运行应用程序创建settingsBarButton时,isAccessibilityElement
返回true,但在测试过程中,返回false。
解决方案
看起来按钮不是导航栏的子视图。
试试app.buttons["settingsBarButton"].tap()
吧。
这个小扩展有时会有所帮助。
extension XCUIElement {
func tapUnhittable() {
XCTContext.runActivity(named: "Tap \(self) by coordinate") { _ in
coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0)).tap()
}
}
}
尝试app.buttons["settingsBarButton"].tapUnhittable()
推荐阅读
- kubernetes - Kubernetes 如何创建一个运行初始化和终止的 sidecar
- regex - 日期的正则表达式没有空格
- c++builder - 保存和恢复画布->笔状态
- image-processing - 如何确定我的图像是亮文本还是暗文本?[LabVIEW]
- css - 将所有 div 定位到以下两层
- ios - 使用 Linkedin SDK iOS 登录
- reactjs - 反应原生:无法解析“@ant-design/icons-react-native/fonts/antoutline.ttf”
- c# - 如何在 C# 中显示一定时间的消息
- java - 为什么 Xamarin.Android 不是在自定义代理上构建,而是在 VSTS 默认 Visual Studio 2017 代理和 Visual Studio 中构建?
- git - 如何从一个远程获取并推送到另一个