Skip to content

Commit

Permalink
Update lock specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 21, 2024
1 parent 1f1085b commit 220c7af
Show file tree
Hide file tree
Showing 3 changed files with 379 additions and 462 deletions.
28 changes: 14 additions & 14 deletions lib/commands/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const UNLOCK_TYPES = /** @type {const} */ ([
PATTERN_UNLOCK,
FINGERPRINT_UNLOCK,
]);
const KEYCODE_NUMPAD_ENTER = 66;
const UNLOCK_WAIT_TIME = 100;
const INPUT_KEYS_WAIT_TIME = 100;
export const KEYCODE_NUMPAD_ENTER = 66;
export const UNLOCK_WAIT_TIME = 100;
export const INPUT_KEYS_WAIT_TIME = 100;
const NUMBER_ZERO_KEYCODE = 7;

/**
Expand Down Expand Up @@ -208,7 +208,7 @@ async function fastUnlock(adb, opts) {
* @param {string} key
* @returns {string}
*/
function encodePassword(key) {
export function encodePassword(key) {
return `${key}`.replace(/\s/gi, '%s');
}

Expand All @@ -217,7 +217,7 @@ function encodePassword(key) {
* @param {string} key
* @returns {string[]}
*/
function stringKeyToArr(key) {
export function stringKeyToArr(key) {
return `${key}`.trim().replace(/\s+/g, '').split(/\s*/);
}

Expand All @@ -226,7 +226,7 @@ function stringKeyToArr(key) {
* @param {AndroidDriverCaps} capabilities
* @returns {Promise<void>}
*/
async function fingerprintUnlock(capabilities) {
export async function fingerprintUnlock(capabilities) {
if ((await this.adb.getApiLevel()) < 23) {
throw new Error('Fingerprint unlock only works for Android 6+ emulators');
}
Expand All @@ -239,7 +239,7 @@ async function fingerprintUnlock(capabilities) {
* @param {AndroidDriverCaps} capabilities
* @returns {Promise<void>}
*/
async function pinUnlock(capabilities) {
export async function pinUnlock(capabilities) {
logger.info(`Trying to unlock device using pin ${capabilities.unlockKey}`);
await this.adb.dismissKeyguard();
const keys = stringKeyToArr(String(capabilities.unlockKey));
Expand Down Expand Up @@ -276,7 +276,7 @@ async function pinUnlock(capabilities) {
* @param {AndroidDriverCaps} capabilities
* @returns {Promise<void>}
*/
async function pinUnlockWithKeyEvent(capabilities) {
export async function pinUnlockWithKeyEvent(capabilities) {
logger.info(`Trying to unlock device using pin with keycode ${capabilities.unlockKey}`);
await this.adb.dismissKeyguard();
const keys = stringKeyToArr(String(capabilities.unlockKey));
Expand All @@ -296,7 +296,7 @@ async function pinUnlockWithKeyEvent(capabilities) {
* @param {AndroidDriverCaps} capabilities
* @returns {Promise<void>}
*/
async function passwordUnlock(capabilities) {
export async function passwordUnlock(capabilities) {
const {unlockKey} = capabilities;
logger.info(`Trying to unlock device using password ${unlockKey}`);
await this.adb.dismissKeyguard();
Expand All @@ -318,7 +318,7 @@ async function passwordUnlock(capabilities) {
* @param {number} piece
* @returns {import('@appium/types').Position}
*/
function getPatternKeyPosition(key, initPos, piece) {
export function getPatternKeyPosition(key, initPos, piece) {
/*
How the math works:
We have 9 buttons divided in 3 columns and 3 rows inside the lockPatternView,
Expand All @@ -342,7 +342,7 @@ function getPatternKeyPosition(key, initPos, piece) {
* @param {number} piece
* @returns {import('./types').TouchAction[]}
*/
function getPatternActions(keys, initPos, piece) {
export function getPatternActions(keys, initPos, piece) {
/** @type {import('./types').TouchAction[]} */
const actions = [];
/** @type {number[]} */
Expand Down Expand Up @@ -398,7 +398,7 @@ function getPatternActions(keys, initPos, piece) {
* @param {import('appium-adb').ADB} adb
* @param {number?} [timeoutMs=null]
*/
async function verifyUnlock(adb, timeoutMs = null) {
export async function verifyUnlock(adb, timeoutMs = null) {
try {
await waitForCondition(async () => !(await adb.isScreenLocked()), {
waitMs: timeoutMs ?? 2000,
Expand All @@ -414,7 +414,7 @@ async function verifyUnlock(adb, timeoutMs = null) {
* @this {import('../driver').AndroidDriver}
* @param {AndroidDriverCaps} capabilities
*/
async function patternUnlock(capabilities) {
export async function patternUnlock(capabilities) {
const {unlockKey} = capabilities;
logger.info(`Trying to unlock device using pattern ${unlockKey}`);
await this.adb.dismissKeyguard();
Expand Down Expand Up @@ -449,7 +449,7 @@ async function patternUnlock(capabilities) {
* @param {AndroidDriverCaps?} [caps=null]
* @returns {Promise<void>}
*/
async function unlockWithOptions(caps = null) {
export async function unlockWithOptions(caps = null) {
if (!(await this.adb.isScreenLocked())) {
logger.info('Screen already unlocked, doing nothing');
return;
Expand Down
Loading

0 comments on commit 220c7af

Please sign in to comment.