【发布时间】:2022-08-05 16:04:56
【问题描述】:
我们的应用程序将在 iPhone 屏幕底部弹出一个系统操作表,如下图所示。我想在 UI 测试中找到并点击该操作表上的“呼叫...”和“取消”按钮。
首先,我尝试添加一个 UI 中断处理程序,并在处理程序闭包中放置一个断点,但在显示操作表时它没有被触发。
// Add an UI interruption handler to handle system alert.
addUIInterruptionMonitor(withDescription: \"Notification permisson request\") { alert in
let notifyAllowBtn = alert.buttons[\"Allow\"]
let callBtn = alert.buttons[\"Call 8663xxxxx\"]
if notifyAllowBtn.exists {
notifyAllowBtn.tap()
return true
}
if callBtn.exists {
callBtn.tap()
return true
}
// A placeholder for other alerts
return true
}
// need to interact with the app again for the handler to fire
app.swipeUp()
此外,我还尝试了 SpringBoard,但仍然没有运气。在此需要帮助,我如何在系统操作表上找到该元素?
let springboard = XCUIApplication(bundleIdentifier: \"com.apple.springboard\")
let alertCallButton = springboard.buttons[\"Call 8663xxxxx\"]
XCTAssert(alertCallButton.waitForExistence(timeout: 5))
-
对我来说,跳板有时会发挥作用,但可能会延迟 30-60 秒 :\'(,有时它在运行比 iOS15 更旧版本的 iOS 的设备上也不起作用。
-
谢谢你的回复。我正在使用版本 15.3.1 的 iPhone 13 Pro 运行此测试。好一点,我会试着等一下跳板,看看它是否可以触发。
-
@stachich,你是对的。添加30秒等待后,可以找到Springboard中的标签和按钮!谢谢伙计,这个问题困扰了我大约 2 天:)
-
没问题的伙伴,很高兴你解决了它:D。这只是迄今为止我遇到的与 xcuitests 相关的许多奇怪事情之一。
标签: ios swift uikit xctest uiactionsheet