How can I Enroll Touch ID in Simulator from the command line?
Asked Answered
S

3

13

I want to enroll Touch ID in the iOS Simulator from the command line so I can run some automated UI feature tests around authorization.

I've tried a few things that didn't work:

  • xcrun simctl doesn't have a Touch ID option
  • an AppleScript to control the menu didn't work because osascript doesn't have accessibility permissions (and I don't like this invasive workaround)
  • I tried editing the simulator's plist before launch but couldn't find an appropriate key value pair

If it matters, I'm using Frank and Cucumber for the tests.

Sellars answered 18/10, 2016 at 20:54 Comment(4)
Pretty sure computers don't have thumbs, dude.Spreadeagle
You can still use osascript to run an AppleScript without nasty hacks. Open the System Preferences and go to Security & Privacy -> Privacy tab. Now add Terminal (or whatever app that you're using to run the script) to the list of apps under "Allow the apps below to control your computer."Teetotum
@Teetotum That would be an acceptable answer if you can show how to do that via the command line (for example using a tool like Ansible).Sellars
@AaronBrager I don't think it's possible via the command line, that's why I didn't add it as an answer. Though you only need to do it one time, so it doesn't need to be a part of your automation process; you can look at it as a prerequisite for the machine that's running the scripts.Teetotum
C
9
xcrun simctl spawn 'iPhone X' notifyutil -s com.apple.BiometricKit.enrollmentChanged '1' && xcrun simctl spawn 'iPhone X' notifyutil -p com.apple.BiometricKit.enrollmentChanged

This will enroll fingerprint. Code taken from here

Edit: You can use this for finger touch:

xcrun simctl spawn 'iPhone X' notifyutil -p com.apple.BiometricKit_Sim.fingerTouch.match
xcrun simctl spawn 'iPhone X' notifyutil -p com.apple.BiometricKit_Sim.fingerTouch.nomatch
Chamade answered 23/5, 2019 at 8:52 Comment(1)
Wow, thanks! Didn’t think this would ever get answered.Sellars
B
2

UPDATE May 2019: Read the accepted answer, that's the way to do it.

Original Answer from 2016: As far as I know there is no way to activate this on the simulator.

Generally, to test something like this, I fake a callback from the Apple component, or pop an alert view if there is no callback expected (like when calling openURL:, I'll pop an alert view with the URL that should be opened to verify the correct thing would be opened when opening that URL) while testing.

It feels kinda hacky, but it at least tells me that if the Apple component is giving me the expected callback, my application will take the expected action.

How do you tell if it's testing? Well, you've got a couple options.

Jon Reid's got a good post about how to tell if you're testing at runtime here: http://qualitycoding.org/app-delegate-for-tests/ - though he's using it to switch out the app delegate, I've used a similar technique to check whether the app is presently under test or not.

I'm not 100% sure this technique would work with Cucumber and Frank since I don't know if they run in the same process as the tests. For things not running in the same process as the tests (such as XCUI tests) I've passed in ProcessInfo arguments when the app is being launched so that it knows what to look for. Pain in the ass, and again, hacky, but it does seem to work.

Biotype answered 21/10, 2016 at 19:43 Comment(0)
A
0

There is a way to do it from the command line (without involving accessibility), but it's also rather invasive (and not very easy). You can use Apple's CoreSimulator framework in a manner similar to what Facebook's FBSimulatorControl project does (but which does not support the touchID enroll feature).

You can see an example Swift script here:

https://github.com/flockoffiles/SimTestCtl/blob/master/SimTestCtl/main.swift

With it you can enroll or unenroll an already booted iOS Simulator (with the given UUID).

Altimetry answered 10/10, 2018 at 8:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.