Zeek Aran
Zeek Aran

Reputation: 626

How to acknowledge system alerts on a device with KIF testing framework?

I found out how to acknowledge system alerts while on a simulator from this post using this line of code:

self.viewTester.acknowledgeSystemAlert()

Unfortunately, the KIF code has #if TARGET_IPHONE_SIMULATOR wrapped around it, so it won't work on a device. How can I get around permission alerts on a device during automated testing?

Upvotes: 4

Views: 514

Answers (1)

Maryam Fekri
Maryam Fekri

Reputation: 625

I had same issue and here the solution I found:

its right than this KIF function doesn't work on device, its only for simulators! so, You can have a UITest in the UITarget and just a single Test case in it that will add a UIMonitors like this:

// ask for all the permission from users then : 
   _ = addUIInterruptionMonitor(withDescription: "") { alert -> Bool in
        let confirmLabels = ["Allow", "OK"]
        for (_, label) in confirmLabels.enumerated() {
            let allow = alert.buttons[label]
            if allow.exists {
                allow.tap()
                break
            }
        }

        return true
    } 
// do some UI interaction here like tapping on some view in app 

So you can call this UITest each time before running your UnitTests and that will prepare your app to have all the permissions.

btw, if anyone has better solution please provide cause I wanna know, too ;)

Upvotes: 2

Related Questions