-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add finger print command to android Driver
- Loading branch information
1 parent
5dab23d
commit 01fe970
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/test/java/io/appium/java_client/android/FingerPrintTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.android; | ||
|
||
import io.appium.java_client.remote.MobileCapabilityType; | ||
import io.appium.java_client.service.local.AppiumDriverLocalService; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FingerPrintTest { | ||
private static AppiumDriverLocalService service; | ||
|
||
/** | ||
* initialization. | ||
*/ | ||
@BeforeClass public static void beforeClass() throws Exception { | ||
service = AppiumDriverLocalService.buildDefaultService(); | ||
service.start(); | ||
|
||
if (service == null || !service.isRunning()) { | ||
throw new ExceptionInInitializerError("An appium server node is not started!"); | ||
} | ||
} | ||
|
||
/** | ||
* finishing. | ||
*/ | ||
@AfterClass public static void afterClass() { | ||
if (service != null) { | ||
service.stop(); | ||
} | ||
} | ||
|
||
/** | ||
* enable system security which is required for finger print activation. | ||
*/ | ||
@Before public void before() throws Exception { | ||
final AndroidDriver driver = getAndroidDriver("ChooseLockGeneric"); | ||
TimeUnit.SECONDS.sleep(2); | ||
// clicking the pin lock mode | ||
driver.findElement(By.xpath("//android.widget.ListView[1]/android.widget.LinearLayout[4]")) | ||
.click(); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.id("com.android.settings:id/next_button")).click(); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.quit(); | ||
} | ||
|
||
/** | ||
* add a new finger print to security. | ||
*/ | ||
@Test public void pressKeyCodeTest() throws Exception { | ||
try { | ||
final AndroidDriver driver = getAndroidDriver(".fingerprint.FingerprintSettings"); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement( | ||
By.xpath("//android.widget.ListView[1]/android.widget.LinearLayout[1]")).click(); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.fingerPrint(2); | ||
driver.findElement(By.id("com.android.settings:id/next_button")).click(); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.quit(); | ||
} catch (Exception ignored) { | ||
Assert.fail(); | ||
} | ||
} | ||
|
||
/** | ||
* disabling pin lock mode. | ||
*/ | ||
@After public void after() throws Exception { | ||
final AndroidDriver driver = getAndroidDriver("ChooseLockGeneric"); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.id("com.android.settings:id/password_entry")).sendKeys("1234\n"); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.xpath("//android.widget.ListView[1]/android.widget.LinearLayout[1]")) | ||
.click(); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.findElement(By.id("android:id/button1")).click(); | ||
TimeUnit.SECONDS.sleep(2); | ||
driver.quit(); | ||
} | ||
|
||
private AndroidDriver getAndroidDriver(String activity) throws Exception { | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); | ||
capabilities.setCapability("appPackage", "com.android.settings"); | ||
capabilities.setCapability("appActivity", activity); | ||
return (AndroidDriver) new AndroidDriver<AndroidElement>(service.getUrl(), capabilities); | ||
} | ||
|
||
} |