Skip to content

Commit 0a3f463

Browse files
Additional changes of the #473:
- AuthenticatesByFinger was added to `io.appium.java_client.android` - Some improvements of the FingerPrintTest
1 parent 48d703c commit 0a3f463

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

src/main/java/io/appium/java_client/PressesKeyCode.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static io.appium.java_client.MobileCommand.longPressKeyCodeCommand;
2020
import static io.appium.java_client.MobileCommand.pressKeyCodeCommand;
21-
import static io.appium.java_client.android.AndroidMobileCommandHelper.fingerPrintCommand;
2221

2322
public interface PressesKeyCode extends ExecutesMethod {
2423

@@ -42,15 +41,6 @@ default void pressKeyCode(int key, Integer metastate) {
4241
CommandExecutionHelper.execute(this, pressKeyCodeCommand(key, metastate));
4342
}
4443

45-
/**
46-
* Authenticate users by using their finger print scans on supported emulators.
47-
*
48-
* @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10)
49-
*/
50-
default void fingerPrint(int fingerPrintId) {
51-
CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId));
52-
}
53-
5444
/**
5545
* Send a long key event to the device.
5646
*

src/main/java/io/appium/java_client/android/AndroidDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class AndroidDriver<T extends WebElement>
4747
extends AppiumDriver<T>
4848
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
4949
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasAndroidSettings, HasDeviceDetails,
50-
HasSupportedPerformanceDataType {
50+
HasSupportedPerformanceDataType, AuthenticatesByFinger {
5151

5252
private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;
5353

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.appium.java_client.android;
2+
3+
import static io.appium.java_client.android.AndroidMobileCommandHelper.fingerPrintCommand;
4+
5+
import io.appium.java_client.CommandExecutionHelper;
6+
import io.appium.java_client.ExecutesMethod;
7+
8+
public interface AuthenticatesByFinger extends ExecutesMethod {
9+
10+
/**
11+
* Authenticate users by using their finger print scans on supported emulators.
12+
*
13+
* @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10)
14+
*/
15+
default void fingerPrint(int fingerPrintId) {
16+
CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId));
17+
}
18+
}

src/test/java/io/appium/java_client/android/FingerPrintTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client.android;
1818

19+
import static java.util.concurrent.TimeUnit.SECONDS;
20+
1921
import io.appium.java_client.remote.MobileCapabilityType;
2022
import io.appium.java_client.service.local.AppiumDriverLocalService;
2123
import org.junit.After;
@@ -28,8 +30,11 @@
2830
import org.openqa.selenium.NoSuchElementException;
2931
import 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+
*/
3338
public 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

Comments
 (0)