forked from webdriverio/appium-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.biometric.login.spec.ts
101 lines (90 loc) · 4.15 KB
/
app.biometric.login.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import TabBar from '../screenobjects/components/TabBar';
import LoginScreen from '../screenobjects/LoginScreen';
import Biometrics from '../helpers/Biometrics';
import NativeAlert from '../screenobjects/components/NativeAlert';
import AndroidSettings from '../screenobjects/AndroidSettings';
/**
* IMPORTANT!
* To verify if Touch/FaceID for iOS and FingerPrint for Android work we need to verify if they are enabled. This can be done by verifying
* if the biometrics button is shown. If not shown we need to enabled it.
* For iOS it's pretty straightforward, but for Android is more complex. There is a helper (Android Settings) that will handle all steps for
* you for Android 7.1 till the latest version of Android.
*/
describe('WebdriverIO and Appium, when interacting with a biometric button,', () => {
beforeEach(() => {
goToLoginPage();
// If the biometry is not shown on iOS, enable it on the phone
if (driver.isIOS && !LoginScreen.biometricButton.isDisplayed()) {
// iOS us pretty straightforward, just enabled it
driver.toggleEnrollTouchId(true);
// restart the app
driver.reset();
// Wait for the app again and go to the login screen
goToLoginPage();
} else if (driver.isAndroid && !LoginScreen.biometricButton.isDisplayed()) {
// Android is more complex, see this method
AndroidSettings.enableBiometricLogin();
// restart the app
driver.reset();
// Wait for the app again and go to the login screen
goToLoginPage();
}
});
it('should be able to login with a matching touch/faceID/fingerprint', () => {
// Always make sure you are on the right tab
LoginScreen.loginContainerButton.click();
// Press the touch/faceID/Fingerprint button
LoginScreen.biometricButton.click();
// This method will successfully handle the biometric login for OR Android, OR iOS.
Biometrics.submitBiometricLogin(true);
// Wait for the alert and validate it
NativeAlert.waitForIsShown();
expect(NativeAlert.text()).toEqual('Success\nYou are logged in!');
// Close the alert
NativeAlert.pressButton('OK');
NativeAlert.waitForIsShown(false);
});
it('should NOT be able to login with a non matching touch/faceID/fingerprint', () => {
// Always make sure you are on the right tab
LoginScreen.loginContainerButton.click();
// Press the touch/faceID/Fingerprint button
LoginScreen.biometricButton.click();
// This method will let the biometric login for OR Android, OR iOS fail.
Biometrics.submitBiometricLogin(false);
// iOS shows an alert, Android doesn't
if (driver.isIOS) {
// Wait for the alert and validate it
NativeAlert.waitForIsShown();
expect(NativeAlert.text()).toContain('Try Again');
// Close the alert
NativeAlert.pressButton('Cancel');
try {
// In certain situations we need to Cancel it again for this specific app
NativeAlert.pressButton('Cancel');
} catch (ign) {
// Do nothing
}
NativeAlert.waitForIsShown(false);
} else {
AndroidSettings.waitAndClick('Cancel');
// When FingerPrint in this app is cancelled on Android 9 and higher it will show the
// FingerPrint modal again. This means it needs to be cancelled again.
// @ts-ignore
if (parseInt(driver.capabilities.platformVersion) > 8){
// This will show the face ID alert again. Let it fail again to make the alert go away.
Biometrics.submitBiometricLogin(false);
AndroidSettings.waitAndClick('Cancel');
}
AndroidSettings.findAndroidElementByText('Cancel').waitForDisplayed({ reverse:true });
NativeAlert.waitForIsShown(false);
}
});
});
/**
* Go to the login screen
*/
function goToLoginPage(){
TabBar.waitForTabBarShown();
TabBar.openLogin();
LoginScreen.waitForIsShown(true);
}