|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * See the NOTICE file distributed with this work for additional |
| 5 | + * information regarding copyright ownership. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.appium.java_client.android; |
| 18 | + |
| 19 | +import io.appium.java_client.remote.MobileCapabilityType; |
| 20 | +import io.appium.java_client.service.local.AppiumDriverLocalService; |
| 21 | +import org.junit.After; |
| 22 | +import org.junit.AfterClass; |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.BeforeClass; |
| 26 | +import org.junit.Test; |
| 27 | +import org.openqa.selenium.By; |
| 28 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 29 | + |
| 30 | +import java.util.concurrent.TimeUnit; |
| 31 | + |
| 32 | +public class FingerPrintTest { |
| 33 | + private static AppiumDriverLocalService service; |
| 34 | + |
| 35 | + /** |
| 36 | + * initialization. |
| 37 | + */ |
| 38 | + @BeforeClass public static void beforeClass() throws Exception { |
| 39 | + service = AppiumDriverLocalService.buildDefaultService(); |
| 40 | + service.start(); |
| 41 | + |
| 42 | + if (service == null || !service.isRunning()) { |
| 43 | + throw new ExceptionInInitializerError("An appium server node is not started!"); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * finishing. |
| 49 | + */ |
| 50 | + @AfterClass public static void afterClass() { |
| 51 | + if (service != null) { |
| 52 | + service.stop(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * enable system security which is required for finger print activation. |
| 58 | + */ |
| 59 | + @Before public void before() throws Exception { |
| 60 | + final AndroidDriver driver = getAndroidDriver("ChooseLockGeneric"); |
| 61 | + TimeUnit.SECONDS.sleep(2); |
| 62 | + // clicking the pin lock mode |
| 63 | + driver.findElement(By.xpath("//android.widget.ListView[1]/android.widget.LinearLayout[4]")) |
| 64 | + .click(); |
| 65 | + TimeUnit.SECONDS.sleep(2); |
| 66 | + driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); |
| 67 | + TimeUnit.SECONDS.sleep(2); |
| 68 | + driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); |
| 69 | + TimeUnit.SECONDS.sleep(2); |
| 70 | + driver.findElement(By.id("com.android.settings:id/next_button")).click(); |
| 71 | + TimeUnit.SECONDS.sleep(2); |
| 72 | + driver.quit(); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * add a new finger print to security. |
| 77 | + */ |
| 78 | + @Test public void pressKeyCodeTest() throws Exception { |
| 79 | + try { |
| 80 | + final AndroidDriver driver = getAndroidDriver(".fingerprint.FingerprintSettings"); |
| 81 | + TimeUnit.SECONDS.sleep(2); |
| 82 | + driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); |
| 83 | + TimeUnit.SECONDS.sleep(2); |
| 84 | + driver.findElement( |
| 85 | + By.xpath("//android.widget.ListView[1]/android.widget.LinearLayout[1]")).click(); |
| 86 | + TimeUnit.SECONDS.sleep(2); |
| 87 | + driver.fingerPrint(2); |
| 88 | + driver.findElement(By.id("com.android.settings:id/next_button")).click(); |
| 89 | + TimeUnit.SECONDS.sleep(2); |
| 90 | + driver.quit(); |
| 91 | + } catch (Exception e) { |
| 92 | + Assert.fail("failed to enable finger print security: " + e.getMessage()); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * disabling pin lock mode. |
| 98 | + */ |
| 99 | + @After public void after() throws Exception { |
| 100 | + final AndroidDriver driver = getAndroidDriver("ChooseLockGeneric"); |
| 101 | + TimeUnit.SECONDS.sleep(2); |
| 102 | + driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); |
| 103 | + TimeUnit.SECONDS.sleep(2); |
| 104 | + driver.findElement(By.xpath("//android.widget.ListView[1]/android.widget.LinearLayout[1]")) |
| 105 | + .click(); |
| 106 | + TimeUnit.SECONDS.sleep(2); |
| 107 | + driver.findElement(By.id("android:id/button1")).click(); |
| 108 | + TimeUnit.SECONDS.sleep(2); |
| 109 | + driver.quit(); |
| 110 | + } |
| 111 | + |
| 112 | + private AndroidDriver getAndroidDriver(String activity) throws Exception { |
| 113 | + DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 114 | + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); |
| 115 | + capabilities.setCapability("appPackage", "com.android.settings"); |
| 116 | + capabilities.setCapability("appActivity", activity); |
| 117 | + return new AndroidDriver<AndroidElement>(service.getUrl(), capabilities); |
| 118 | + } |
| 119 | + |
| 120 | +} |
0 commit comments