如何从 UI 测试访问 Apple Id "Sign In" 对话框?
How to access Apple Id "Sign In" dialog from UI Test?
我有一些 UI 测试,想测试当我按下 "subscribe" 按钮时会发生什么。在模拟器中,会显示一条警告,要求使用 apple id 登录:
我尝试使用 app.alerts["Sign In"]
谓词和 addUIInterruptionMonitor
函数等待警报。没有运气。我什至试图等待 "Cancel" 按钮出现,这也没有用。
知道如何处理此警报并按 "Cancel" 吗?
此警报的问题在于它不是从您的应用创建的,而是从系统应用创建的 - Springboard。因此,为了能够从该应用程序查询元素,您必须使用 Springboard 包 ID 创建 XCUIApplication
对象:
let springboardApp = XCUIApplication(bundleIdentifier: "com.apple.springboard")
然后,找到您的警报:
let signInAlert = springboardApp.alerts.element
然后您应该能够找到 取消 按钮:
signInAlert.buttons["Cancel"].tap()
我有一些 UI 测试,想测试当我按下 "subscribe" 按钮时会发生什么。在模拟器中,会显示一条警告,要求使用 apple id 登录:
我尝试使用 app.alerts["Sign In"]
谓词和 addUIInterruptionMonitor
函数等待警报。没有运气。我什至试图等待 "Cancel" 按钮出现,这也没有用。
知道如何处理此警报并按 "Cancel" 吗?
此警报的问题在于它不是从您的应用创建的,而是从系统应用创建的 - Springboard。因此,为了能够从该应用程序查询元素,您必须使用 Springboard 包 ID 创建 XCUIApplication
对象:
let springboardApp = XCUIApplication(bundleIdentifier: "com.apple.springboard")
然后,找到您的警报:
let signInAlert = springboardApp.alerts.element
然后您应该能够找到 取消 按钮:
signInAlert.buttons["Cancel"].tap()