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

screen off before wake up to clean text field, avoid no element crash #498

Merged
merged 3 commits into from
Feb 5, 2019

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Feb 4, 2019

When I tried to pin unlock:

  • some devices approve after entering pin-code, 4 digits, automatically.
    • Then, clicking element raises an exception
  • pin failed if pin text field already has texts before starting to input digits
  • some devices have a different enter button for pin code such as Samsung devices

To avoid the error, I did:

  • Call KEYCODE_POWER before wake up
    • If the text field has texts, the texts will be clean after wake up
    • If the screen already off, the screen will be on. Calling wakeup after that does not affect device state
  • Calling KEYCODE_NUMPAD_ENTER when we tap enter key
    • It can work for Samsung devices and some other devices I can test
      • The keycode equals to clicking id/key_enter
  • Calling KEYCODE_NUMPAD_ENTER after checking screen lock

I tested:

  • emulators: API 20, 21, 26
  • real devices: API 22, 25, Samsung device

They worked well than before. I'm not sure this can cover all of android devices though...
(I have no mush Chinese devices, for example..)

const el = await driver.findElOrEls('xpath', "//*[contains(@resource-id, 'id/key_enter')]", false);
await driver.click(util.unwrapElement(el));
// Waits a bit for the device to be unlocked
// Some devices accept the entered key automatically
await sleep(UNLOCK_WAIT_TIME);
Copy link
Member Author

@KazuCocoa KazuCocoa Feb 4, 2019

Choose a reason for hiding this comment

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

When I rushed commands without this wait before pressKeyCode, rarely UI2 sever crashed.
Thus, I leave this and call isScreenLocked after this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add this note as the comment in the code

@@ -9,6 +9,8 @@ const PATTERN_UNLOCK = 'pattern';
const FINGERPRINT_UNLOCK = 'fingerprint';
const UNLOCK_TYPES = [PIN_UNLOCK, PASSWORD_UNLOCK, PATTERN_UNLOCK, FINGERPRINT_UNLOCK];
const KEYCODE_NUMPAD_ENTER = '66';
const KEYCODE_POWER = '26';
const KEYCODE_WAKEUP = '224'; // Can work over API Level 20
Copy link
Contributor

Choose a reason for hiding this comment

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

key codes may be integers

Copy link
Member Author

Choose a reason for hiding this comment

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

Either worked fine. I defined as string because of the previous implementation.
I ensured this worked, including KEYCODE_NUMPAD_ENTER, worked as int as well.

const el = await driver.findElOrEls('xpath', "//*[contains(@resource-id, 'id/key_enter')]", false);
await driver.click(util.unwrapElement(el));
// Waits a bit for the device to be unlocked
// Some devices accept the entered key without enter key.
Copy link
Contributor

Choose a reason for hiding this comment

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

...accept entering the code without pressing the Enter key

@KazuCocoa KazuCocoa merged commit f987b1d into appium:master Feb 5, 2019
@KazuCocoa KazuCocoa deleted the km/make-unlock-pin-reliable branch February 5, 2019 11:52
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.

None yet

2 participants