swift 如何允许在UITest中进行跟踪?

cbjzeqam  于 2023-04-04  发布在  Swift
关注(0)|答案(2)|浏览(116)

我已经尝试调用“addUIInterruptionMonitor”应用程序跟踪透明度通知,但它不注册,并为我的下一步失败.任何帮助,对这个对话框的描述是有帮助的,“系统对话框”不工作.
“允许...在其他公司的应用程序和网站上跟踪您的活动”“要求应用程序不要跟踪”“允许”

addUIInterruptionMonitor(withDescription: "System dialog") {
        (alert) -> Bool in
        if alert.buttons["Cancel"].exists {
            alert.buttons["Cancel"].tap()
            self.app.activate()
            return true
        }
        
        return false
    }

q35jwt9p

q35jwt9p1#

找到了解决方案,我用的描述是“跟踪使用权限警报”
测试本身也有一个问题,就是等待一个按钮出现,而这个按钮只有在回答这个对话框时才会出现

addUIInterruptionMonitor(withDescription: "Tracking Usage Permission Alert") {
        (alert) -> Bool in
        if alert.buttons["Allow"].exists {
            alert.buttons["Allow"].tap()
            self.app.activate()
            return true
        }
        return false    
    }
4dc9hkyq

4dc9hkyq2#

您可以尝试通过springboard查找警报。
下面的代码为我工作。

let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
// Alert Query
let permissionAlert = springboard.alerts["Allow “Your App Display Name” to track your activity across other companies’ apps and websites?"].firstMatch
// Check for existence
XCTAssertTrue(permissionAlert.waitForExistence(timeout: 1.0))
// Alert button query
let dialogButton = permissionAlert.buttons["Ask App Not to Track"].firstMatch
// Check for existance
XCTAssertTrue(dialogButton.waitForExistence(timeout: 1.0))
// Tap the button
dialogButton.tap()

希望这个有用。

相关问题