forked from webdriverio/appium-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.biometric.login.spec.ts
More file actions
103 lines (92 loc) · 4.51 KB
/
app.biometric.login.spec.ts
File metadata and controls
103 lines (92 loc) · 4.51 KB
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
102
103
import TabBar from '../screenobjects/components/TabBar.js';
import LoginScreen from '../screenobjects/LoginScreen.js';
import Biometrics from '../helpers/Biometrics.js';
import NativeAlert from '../screenobjects/components/NativeAlert.js';
import AndroidSettings from '../screenobjects/AndroidSettings.js';
/**
* 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(async () => {
await goToLoginPage();
// If the biometry is not shown on iOS, enable it on the phone
if (driver.isIOS && !(await LoginScreen.isBiometricButtonDisplayed())) {
// iOS us pretty straightforward, just enabled it
await driver.toggleEnrollTouchId(true);
// restart the app
// @ts-expect-error command deprecated
await driver.reset();
// Wait for the app again and go to the login screen
await goToLoginPage();
} else if (driver.isAndroid && !(await LoginScreen.isBiometricButtonDisplayed())) {
// Android is more complex, see this method
await AndroidSettings.enableBiometricLogin();
// restart the app
// @ts-expect-error command deprecated
await driver.reset();
// Wait for the app again and go to the login screen
await goToLoginPage();
}
});
it('should be able to login with a matching touch/faceID/fingerprint', async () => {
// Always make sure you are on the right tab
await LoginScreen.tapOnLoginContainerButton();
// Press the touch/faceID/Fingerprint button
await LoginScreen.tapOnBiometricButton();
// This method will successfully handle the biometric login for OR Android, OR iOS.
await Biometrics.submitBiometricLogin(true);
// Wait for the alert and validate it
await NativeAlert.waitForIsShown();
await expect(await NativeAlert.text()).toContain('Success\nYou are logged in!');
// Close the alert
await NativeAlert.topOnButtonWithText('OK');
await NativeAlert.waitForIsShown(false);
});
it('should NOT be able to login with a non matching touch/faceID/fingerprint', async () => {
// Always make sure you are on the right tab
await LoginScreen.tapOnLoginContainerButton();
// Press the touch/faceID/Fingerprint button
await LoginScreen.tapOnBiometricButton();
// This method will let the biometric login for OR Android, OR iOS fail.
await Biometrics.submitBiometricLogin(false);
// iOS shows an alert, Android doesn't
if (driver.isIOS) {
// Wait for the alert and validate it
await NativeAlert.waitForIsShown();
await expect(await NativeAlert.text()).toContain('Try Again');
// Close the alert
await NativeAlert.topOnButtonWithText('Cancel');
try {
// In certain situations we need to Cancel it again for this specific app
await NativeAlert.topOnButtonWithText('Cancel');
} catch (ign) {
// Do nothing
}
await NativeAlert.waitForIsShown(false);
} else {
await AndroidSettings.waitAndTap('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.
await Biometrics.submitBiometricLogin(false);
await AndroidSettings.waitAndTap('Cancel');
}
await (await AndroidSettings.findAndroidElementByText('Cancel')).waitForDisplayed({ reverse:true });
await NativeAlert.waitForIsShown(false);
}
});
});
/**
* Go to the login screen
*/
async function goToLoginPage(){
await TabBar.waitForTabBarShown();
await TabBar.openLogin();
await LoginScreen.waitForIsShown(true);
}