Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 805
Aaron Brager Avatar asked Oct 18 '16 20:10

Aaron Brager


People also ask

How do I enable Touch ID in simulator?

To enable this feature, the allowTouchIdEnroll desired capability must be set to true. When allowTouchIdEnroll is set to true the Simulator will be enrolled by default, and the 'Toggle Touch ID Enrollment' changes the enrollment state. Another way to enable touch id is by using mobile: enrollBiometric . More info here.

How do I open the simulator in terminal?

Just type this command in Terminal: open -a Simulator. app to launch the most recent simulator. Type this command in Terminal to run the Simulator rigth from the its folder.

How do you tap in iOS simulator?

When in the simulator, hold the option key down and click - this will simulate a two-finger tap!


2 Answers

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
like image 89
Pavol Avatar answered Sep 21 '22 14:09

Pavol


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.

like image 42
DesignatedNerd Avatar answered Sep 17 '22 14:09

DesignatedNerd