Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pinWithKeyEvent to put keys one by one for pin as key evnets #691

Merged
merged 7 commits into from
May 5, 2021

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented May 5, 2021

Some devices like Samsung have customized keyboard in pin.
Then, it is reliable to send keys as keycode like password rather than finding numbers with ids. I named the strategy as pinWithKeyEvent for now. (Suggestions are welcome)

As backward compatibility, pin should be there, but the pinUnlockWithKeyEvent can be used as a fallback method when no system key ids in the pin view. Afaik, this fallback is pretty enough.


After this change:

const KEYCODE_NUMPAD_ENTER = 66;
const KEYCODE_POWER = 26;
const KEYCODE_WAKEUP = 224; // Can work over API Level 20
const UNLOCK_WAIT_TIME = 100;
const HIDE_KEYBOARD_WAIT_TIME = 100;
const INPUT_KEYS_WAIT_TIME = 100;
// mapping of Android keycode and numbers
const ANDROID_KEY_CODE_NUMBER = {
'0': 7,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this mapping could be generated dynamically, there is no need to hardcode each item

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ZERO_KEY_CODE = 7;
result = _.range(10).reduce((acc) => {
  acc[String.fromCharCode('0'.charCodeAt(0) + _.size(acc))] = ZERO_KEY_CODE + _.size(acc);
  return acc;
}, {});


// Some devices accept entering the code without pressing the Enter key
// When I rushed commands without this wait before pressKeyCode, rarely UI2 sever crashed
await sleep(UNLOCK_WAIT_TIME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we extract this duplicated block into a separate function to avoid duplication?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@KazuCocoa KazuCocoa merged commit 9493a75 into appium:master May 5, 2021
@KazuCocoa KazuCocoa deleted the add-pin-with-keyevent branch May 5, 2021 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants