How do you get past permissions in UI tests?

Hi guys,


I am trying to get past permissions pop-ups in the setup of my app, but can't really go further. The app that i'm testing on needs Location, Motion&Fitness and VPN permissions. I know that the XCTest allows permissions by default, but does not seam to work anymore, from what i saw it is because not all permission pop-ups have an Allow button. I managed to make it work from the code for the Push Notifications permission using the bellow code, but does not seam to work for the others. Anyone else has this problem?



addUIInterruptionMonitor(withDescription: "Push Notifications") { (alert) -> Bool in

alert.buttons["Allow"].tap()

return true

}

app.buttons["bottom_button"].tap()

app.tap()

Replies

I've ended up using code that uses a list of button names.


addUIInterruptionMonitor(withDescription: "alert handler") { (alert: XCUIElement) -> Bool in

let confirmLabels = ["Allow", "OK", "Tillat"]

for (_, label) in confirmLabels.enumerated() {

let allow = alert.buttons[label]

if allow.exists {

allow.tap()

break

}

}


return true

}

app.tap()