XCUITest Sign in with apple

I'm trying to automate a testing flow in my app, that requires signing in with apple first. I've figure out how open settings and login with a test apple ID. I've wrapped that up in a function and call that first (with a check to see if its already logged in). When I return to my app, and tapping the sign in with apple button, I can't find anyway to interact with the sign in with apple modal, e.g. asking me if I want to share my email address or not, tapping "continue with password" and so on

I've tried setting up an interruption handler, but it doesn't get triggered

let test = addUIInterruptionMonitor(withDescription: "") { alert in
			
			print("inside alert:\( alert )")
			
			return true
}

I've tried checking for springboard alerts, but its not an alert

let springboardApp = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboardApp.alerts.exists

I don't know any other tricks, or how to find the bundle ID of this popup. Any advice?

Answered by simonmcl in 760853022

Managed to find the bundle identifier needed com.apple.AuthKitUIService

This is not a complete solution that handles all paths through the modal. Just a sample to get through the flow when you have previously signed in. Just leaving this here to show how to wrap something like this up in a function

sleep(4)
let testApp = XCUIApplication(bundleIdentifier: "com.apple.AuthKitUIService")
        
let continueButton = testApp.buttons["Continue"]
if continueButton.exists {
    continueButton.tap()
}
        
let shareEmailOption = testApp.tables.staticTexts["Share My Email"]
if shareEmailOption.exists {
    shareEmailOption.tap()
}
        
let continueWithPassword = testApp.buttons["Continue with Password"]
if continueWithPassword.exists {
    continueWithPassword.tap()
}
        
testApp.secureTextFields["Password"].tap()

// Type your password

testApp.buttons["Sign In"].tap()

// Wait for something to show up in your app to denote success / failure
let app = XCUIApplication()
.......

How I found this bundle identifier for anyone having similar issues:

running xcrun simctl list devices --json in terminal lists all simulators. Find the UDID of the one you are using then either:

run xcrun simctl listapps <UDID>

or go to ~/Library/Developer/CoreSimulator/<UDID>/data/Containers/Data and do a search for "com.apple"

Accepted Answer

Managed to find the bundle identifier needed com.apple.AuthKitUIService

This is not a complete solution that handles all paths through the modal. Just a sample to get through the flow when you have previously signed in. Just leaving this here to show how to wrap something like this up in a function

sleep(4)
let testApp = XCUIApplication(bundleIdentifier: "com.apple.AuthKitUIService")
        
let continueButton = testApp.buttons["Continue"]
if continueButton.exists {
    continueButton.tap()
}
        
let shareEmailOption = testApp.tables.staticTexts["Share My Email"]
if shareEmailOption.exists {
    shareEmailOption.tap()
}
        
let continueWithPassword = testApp.buttons["Continue with Password"]
if continueWithPassword.exists {
    continueWithPassword.tap()
}
        
testApp.secureTextFields["Password"].tap()

// Type your password

testApp.buttons["Sign In"].tap()

// Wait for something to show up in your app to denote success / failure
let app = XCUIApplication()
.......

How I found this bundle identifier for anyone having similar issues:

running xcrun simctl list devices --json in terminal lists all simulators. Find the UDID of the one you are using then either:

run xcrun simctl listapps <UDID>

or go to ~/Library/Developer/CoreSimulator/<UDID>/data/Containers/Data and do a search for "com.apple"

XCUITest Sign in with apple
 
 
Q