-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Drop obsolete Simulator versions (#420)
BREAKING CHANGE: Dropped obsolete simulator classes: SimulatorXcode8, SimulatorXcode9 and SimulatorXcode9_3. APIs that are still relevant have been moved to SimulatorXcode10 BREAKING CHANGE: Added proper type definitions. Interfaces were refactored and connected to appropriate extension classes. Now it is possible to provide a logger to the factory method, which improves the visibility of session identifiers
- Loading branch information
1 parent
723f16f
commit bff7e56
Showing
27 changed files
with
1,691 additions
and
1,846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,80 @@ | ||
import _ from 'lodash'; | ||
import log from '../logger'; | ||
|
||
const extensions = {}; | ||
const ENROLLMENT_NOTIFICATION_RECEIVER = 'com.apple.BiometricKit.enrollmentChanged'; | ||
const BIOMETRICS = { | ||
touchId: 'fingerTouch', | ||
faceId: 'pearl', | ||
}; | ||
|
||
/** | ||
* Get the current state of Biometric Enrollment feature. | ||
* | ||
* @returns {Promise<boolean>} Either true or false | ||
* @throws {Error} If Enrollment state cannot be determined | ||
* @this {CoreSimulatorWithBiometric} | ||
* @returns {Promise<boolean>} | ||
*/ | ||
extensions.isBiometricEnrolled = async function isBiometricEnrolled () { | ||
const output = await this.executeUIClientScript(` | ||
tell application "System Events" | ||
tell process "Simulator" | ||
set dstMenuItem to menu item "Toggle Enrolled State" of menu 1 of menu item "Touch ID" of menu 1 of menu bar item "Hardware" of menu bar 1 | ||
set isChecked to (value of attribute "AXMenuItemMarkChar" of dstMenuItem) is "✓" | ||
end tell | ||
end tell | ||
`); | ||
log.debug(`Touch ID enrolled state: ${output}`); | ||
return _.isString(output) && output.trim() === 'true'; | ||
}; | ||
export async function isBiometricEnrolled () { | ||
const {stdout} = await this.simctl.spawnProcess([ | ||
'notifyutil', | ||
'-g', ENROLLMENT_NOTIFICATION_RECEIVER | ||
]); | ||
const match = (new RegExp(`${_.escapeRegExp(ENROLLMENT_NOTIFICATION_RECEIVER)}\\s+([01])`)) | ||
.exec(stdout); | ||
if (!match) { | ||
throw new Error(`Cannot parse biometric enrollment state from '${stdout}'`); | ||
} | ||
this.log.info(`Current biometric enrolled state for ${this.udid} Simulator: ${match[1]}`); | ||
return match[1] === '1'; | ||
} | ||
|
||
/** | ||
* Enrolls biometric (TouchId, FaceId) feature testing in Simulator UI client. | ||
* | ||
* @param {boolean} isEnabled - Defines whether biometric state is enabled/disabled | ||
* @throws {Error} If the enrolled state cannot be changed | ||
* @this {CoreSimulatorWithBiometric} | ||
* @param {boolean} isEnabled | ||
*/ | ||
extensions.enrollBiometric = async function enrollBiometric (isEnabled = true) { | ||
await this.executeUIClientScript(` | ||
tell application "System Events" | ||
tell process "Simulator" | ||
set dstMenuItem to menu item "Toggle Enrolled State" of menu 1 of menu item "Touch ID" of menu 1 of menu bar item "Hardware" of menu bar 1 | ||
set isChecked to (value of attribute "AXMenuItemMarkChar" of dstMenuItem) is "✓" | ||
if ${isEnabled ? 'not ' : ''}isChecked then | ||
click dstMenuItem | ||
end if | ||
end tell | ||
end tell | ||
`); | ||
}; | ||
export async function enrollBiometric (isEnabled = true) { | ||
this.log.debug(`Setting biometric enrolled state for ${this.udid} Simulator to '${isEnabled ? 'enabled' : 'disabled'}'`); | ||
await this.simctl.spawnProcess([ | ||
'notifyutil', | ||
'-s', ENROLLMENT_NOTIFICATION_RECEIVER, isEnabled ? '1' : '0' | ||
]); | ||
await this.simctl.spawnProcess([ | ||
'notifyutil', | ||
'-p', ENROLLMENT_NOTIFICATION_RECEIVER | ||
]); | ||
if (await this.isBiometricEnrolled() !== isEnabled) { | ||
throw new Error(`Cannot set biometric enrolled state for ${this.udid} Simulator to '${isEnabled ? 'enabled' : 'disabled'}'`); | ||
} | ||
} | ||
|
||
/** | ||
* Sends a notification to match/not match the touch id. | ||
* Sends a notification to match/not match the particular biometric. | ||
* | ||
* @param {?boolean} shouldMatch [true] - Set it to true or false in order to emulate | ||
* @this {CoreSimulatorWithBiometric} | ||
* @param {boolean} shouldMatch [true] - Set it to true or false in order to emulate | ||
* matching/not matching the corresponding biometric | ||
* @param {string} biometricName [touchId] - Either touchId or faceId (faceId is only available since iOS 11) | ||
*/ | ||
extensions.sendBiometricMatch = async function sendBiometricMatch (shouldMatch = true) { | ||
await this.executeUIClientScript(` | ||
tell application "System Events" | ||
tell process "Simulator" | ||
set dstMenuItem to menu item "${shouldMatch ? 'Matching Touch' : 'Non-matching Touch'}" of menu 1 of menu item "Touch ID" of menu 1 of menu bar item "Hardware" of menu bar 1 | ||
click dstMenuItem | ||
end tell | ||
end tell | ||
`); | ||
}; | ||
export async function sendBiometricMatch (shouldMatch = true, biometricName = 'touchId') { | ||
const domainComponent = toBiometricDomainComponent(biometricName); | ||
const domain = `com.apple.BiometricKit_Sim.${domainComponent}.${shouldMatch ? '' : 'no'}match`; | ||
await this.simctl.spawnProcess([ | ||
'notifyutil', | ||
'-p', domain | ||
]); | ||
this.log.info( | ||
`Sent notification ${domain} to ${shouldMatch ? 'match' : 'not match'} ${biometricName} biometric ` + | ||
`for ${this.udid} Simulator` | ||
); | ||
} | ||
|
||
export default extensions; | ||
/** | ||
* @param {string} name | ||
* @returns {string} | ||
*/ | ||
export function toBiometricDomainComponent (name) { | ||
if (!BIOMETRICS[name]) { | ||
throw new Error(`'${name}' is not a valid biometric. Use one of: ${JSON.stringify(_.keys(BIOMETRICS))}`); | ||
} | ||
return BIOMETRICS[name]; | ||
} | ||
|
||
/** | ||
* @typedef {import('../types').CoreSimulator & import('../types').SupportsBiometric} CoreSimulatorWithBiometric | ||
*/ |
Oops, something went wrong.