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 ( async ( ) => { await goToLoginPage ( ) ; if ( driver . isIOS && ! ( await LoginScreen . isBiometricButtonDisplayed ( ) ) ) { await driver . toggleEnrollTouchId ( true ) ; await driver . reset ( ) ; await goToLoginPage ( ) ; } else if ( driver . isAndroid && ! ( await LoginScreen . isBiometricButtonDisplayed ( ) ) ) { await AndroidSettings . enableBiometricLogin ( ) ; await driver . reset ( ) ; await goToLoginPage ( ) ; } } ) ; it ( 'should be able to login with a matching touch/faceID/fingerprint' , async ( ) => { await LoginScreen . tapOnLoginContainerButton ( ) ; await LoginScreen . tapOnBiometricButton ( ) ; await Biometrics . submitBiometricLogin ( true ) ; await NativeAlert . waitForIsShown ( ) ; await expect ( await NativeAlert . text ( ) ) . toContain ( 'Success\nYou are logged in!' ) ; await NativeAlert . topOnButtonWithText ( 'OK' ) ; await NativeAlert . waitForIsShown ( false ) ; } ) ; it ( 'should NOT be able to login with a non matching touch/faceID/fingerprint' , async ( ) => { await LoginScreen . tapOnLoginContainerButton ( ) ; await LoginScreen . tapOnBiometricButton ( ) ; await Biometrics . submitBiometricLogin ( false ) ; if ( driver . isIOS ) { await NativeAlert . waitForIsShown ( ) ; await expect ( await NativeAlert . text ( ) ) . toContain ( 'Try Again' ) ; await NativeAlert . topOnButtonWithText ( 'Cancel' ) ; try { await NativeAlert . topOnButtonWithText ( 'Cancel' ) ; } catch ( ign ) { } await NativeAlert . waitForIsShown ( false ) ; } else { await AndroidSettings . waitAndTap ( 'Cancel' ) ; if ( parseInt ( driver . capabilities . platformVersion ) > 8 ) { 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 ) ; }