1616
1717package io .appium .java_client .android ;
1818
19+ import static java .util .concurrent .TimeUnit .SECONDS ;
20+
1921import io .appium .java_client .remote .MobileCapabilityType ;
2022import io .appium .java_client .service .local .AppiumDriverLocalService ;
2123import org .junit .After ;
2830import org .openqa .selenium .NoSuchElementException ;
2931import org .openqa .selenium .remote .DesiredCapabilities ;
3032
31- import java .util .concurrent .TimeUnit ;
32-
33+ /**
34+ * It is necessary to make this test passing
35+ * - emulator API Level 23 Nexus device
36+ * - perform 'adb emu finger touch' 1 on Windows
37+ */
3338public class FingerPrintTest {
3439
3540 private static final String PASSWORD_INPUT_ID = "com.android.settings:id/password_entry" ;
@@ -62,17 +67,15 @@ public class FingerPrintTest {
6267 */
6368 @ Before public void before () throws Exception {
6469 final AndroidDriver driver = getAndroidDriver ("ChooseLockGeneric" );
65- TimeUnit .SECONDS .sleep (2 );
6670 // clicking the pin lock mode
6771 driver .findElement (By .xpath ("//android.widget.LinearLayout[4]" )).click ();
68- TimeUnit .SECONDS .sleep (2 );
6972 try {
7073 // line below will throw exception if secure startup window is popped up
7174 driver .findElementById (PASSWORD_INPUT_ID );
7275 } catch (NoSuchElementException e ) {
7376 // in secure startup window
7477 driver .findElementById ("com.android.settings:id/encrypt_require_password" ).click ();
75- TimeUnit . SECONDS .sleep (2 );
78+ SECONDS .sleep (2 );
7679 clickOKInPopup (driver );
7780 clickNext (driver );
7881 }
@@ -87,13 +90,10 @@ public class FingerPrintTest {
8790 */
8891 @ Test public void pressKeyCodeTest () throws InterruptedException {
8992 final AndroidDriver driver = getAndroidDriver (".fingerprint.FingerprintSettings" );
90- TimeUnit .SECONDS .sleep (2 );
9193 enterPasswordAndContinue (driver );
9294 // click add fingerprint
9395 driver .findElementByXPath (FIRST_IN_LIST_XPATH ).click ();
94- TimeUnit .SECONDS .sleep (2 );
9596 driver .fingerPrint (2 );
96- TimeUnit .SECONDS .sleep (2 );
9797 try {
9898 clickNext (driver );
9999 } catch (Exception e ) {
@@ -108,34 +108,31 @@ public class FingerPrintTest {
108108 */
109109 @ After public void after () throws InterruptedException {
110110 final AndroidDriver driver = getAndroidDriver ("ChooseLockGeneric" );
111- TimeUnit .SECONDS .sleep (2 );
112111 enterPasswordAndContinue (driver );
113112 driver .findElementByXPath (FIRST_IN_LIST_XPATH ).click ();
114- TimeUnit .SECONDS .sleep (2 );
115113 clickOKInPopup (driver );
116114 driver .quit ();
117115 }
118116
119- private AndroidDriver getAndroidDriver (String activity ) {
117+ private static AndroidDriver getAndroidDriver (String activity ) {
120118 DesiredCapabilities capabilities = new DesiredCapabilities ();
121119 capabilities .setCapability (MobileCapabilityType .DEVICE_NAME , "Android Emulator" );
122120 capabilities .setCapability ("appPackage" , "com.android.settings" );
123121 capabilities .setCapability ("appActivity" , activity );
124- return new AndroidDriver <AndroidElement >(service .getUrl (), capabilities );
122+ AndroidDriver <AndroidElement > driver = new AndroidDriver <AndroidElement >(service .getUrl (), capabilities );
123+ driver .manage ().timeouts ().implicitlyWait (15 , SECONDS );
124+ return driver ;
125125 }
126126
127127 private void enterPasswordAndContinue (AndroidDriver driver ) throws InterruptedException {
128128 driver .findElementById (PASSWORD_INPUT_ID ).sendKeys ("1234\n " );
129- TimeUnit .SECONDS .sleep (2 );
130129 }
131130
132131 private void clickNext (AndroidDriver driver ) throws InterruptedException {
133132 driver .findElementById ("com.android.settings:id/next_button" ).click ();
134- TimeUnit .SECONDS .sleep (2 );
135133 }
136134
137135 private void clickOKInPopup (AndroidDriver driver ) throws InterruptedException {
138136 driver .findElementById ("android:id/button1" ).click ();
139- TimeUnit .SECONDS .sleep (2 );
140137 }
141138}
0 commit comments