Automate adding finger prints for biometric adb commands.
2 min readSep 3, 2020
Note : This solution will only work for emulator.
Installations:
Step 1: Start an emulator using android studio or any emulator.
Step 2: Initiate a driver in your code as
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "android");
caps.setCapability("deviceName", "Pixel3");
caps.setCapability("appPackage", "com.android.settings");
caps.setCapability("appActivity","com.android.settings.Settings");
caps.setCapability("automationName","uiautomator2");
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Step 4:Add same capabilities in your appium desktop and save it.
Start appium sever.
Step 5: Write a function in your code to run the adb commands
private void executeCommand(String cmd){
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", cmd);
try {
Process process = processBuilder.start();
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
BufferedReader ereader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
String eline;
while ((eline = ereader.readLine()) != null) {
output.append(eline + "\n");
}
int exitCode = process.waitFor();
if (exitCode == 0) {
System.out.println("Success");
System.out.println(output);
} else {
System.out.println("Failure");
System.out.println(output);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Step 6: Navigate to the add fingerprint screen from your code and call the above function.
for (int i = 1; i <= 3; i++)
{
Thread.sleep(5000);
executeCommand("adb -e emu finger touch 1");
}
Use driver.fingerPrint(1) to pass the test using added fingerprint.