App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Get Started free
Home Guide How to test Biometric authentication using Appium?

How to test Biometric authentication using Appium?

By Pawan Kumar, Community Contributor -

Appium is an open source solution for cross-platform automation testing of mobile applications. For Android and iOS mobile applications, it now offers a smooth automation testing experience. Appium functions similarly to a node.js server. It was a CLI-only program mostly installed using the node package management a few years ago.

At its core, Appium uses an HTTP server that provides REST API. The client uses REST APIs to interface with the Appium server, which Mobile JSON Wire Protocol handles.

Appium OverViewImportance of Testing Biometric Authentication

There are many advantages to Biometric authentication testing in the mobile app:

  • Verify functionality and security of biometrics
  • Validate Accurate Identification and Authentication.
  • Enhanced User Experience
  • Test biometrics with real-world intervention like phone calls, messages, and notifications
  • Verify the compatibility of biometric-driven mobile applications with various devices, platforms, and operating systems

Top 3 Challenges in Testing Fingerprint Authentication

The fingerprint revolution is instigative for mobile software inventors. Yet integrating biometric technologies data into mobile operations also challenges QA brigades. They include the following:

1. Compatibility Issues with different Devices/OS

Fingerprint isn’t compatible with all types of zilch and bias. So it’s veritably delicate to find a proper device to test fingerprints. 

  • Android frame includes support for face and fingerprint authentication. Android may be customized to support other biometric modules( similar to Iris). Still, the biometric system combination will depend on biometric security, not modality.
  • iOS requires that the device undergoes a registration procedure with the Touch ID or Face ID service before using the authentication tackle. still, device registration isn’t supported for bias running iOS 15 or later. point simulation works with any Android or iOS device that supports the tackle point anthology.

2. Security concerns while testing Sensitive Data

QA teams must work alongside security engineers and legal advisors to ensure mobile applications responsibly handle biometric data. 

  • Beyond simply complying with system conditions, it may be helpful for testing teams to implement usability testing with biometric data to determine which data users are comfortable with for collection and ensure that users can opt out of biometric functionality when appropriate. 
  • This type of testing may not be the first that comes to mind when you think of usability.
  • Still, from the user’s perspective, ensuring a positive experience and avoiding issues about spyware or privacy invasion by a mobile application is crucial.

3. Limitations of Emulator/Simulators in testing Biometric authentication  

One remarkable practical difference that arises from biometric data in mobile devices is that, in difference to other types of input, biometric data can be hard to mimic when you run tests on simulated or emulated mobile devices. 

  • This is one reason why having real devices or an actual device cloud available for testing is so crucial in a biometric-driven world. Failing that, biometric data could still be fed to a mobile test environment inside a simulator or emulator. 
  • However, at some point before the application’s release, testing on real hardware with real biometric input devices is still preferable because sustaining data into a simulated test environment artificially does not allow you to test all of the variables that are at play when you’re dealing with biometric data that is input directly via hardware.

Preparation for Appium Fingerprint testing

If you’re wondering how to automate fingerprint using Appium, let’s get into the initial steps

Prerequisites for testing 

Appium fingerprint authentication following are prerequisites:

  1. Install any programming languages (Java/python/ruby/c#) (Here we are using python)
  2. Android Studio for emulator 
  3. Android Application with a fingerprint feature
  4. Install any code editor (Here we are using pycharm)
  5. Install Appium for testing 

Setting up the Test environment

After installing all prerequisites, follow the below steps for setup environment:

  1. Create a project in pycharm : open pycharm→ open file → click new project → select location of project → enter name of project → click on create button.  setting up the test enviroment 1
  2. Now install appium lib for python : open terminal → enter command (pip install Appium-Python-Client).

Setting up the emulator for fingerprint testing

  1. Create an emulator in android studio which is compatible with the fingerprint feature.
  2. Open that emulator 
  3. Go to Settings → Security & Location → Fingerprint → Next → Fingerprint +pin → confirm pin.
  4. After confirming the pin, we must provide the required fingerprint impression in the emulator. For that follow the below steps:

a. Click on three dots (…) in the emulator menu optionsetting up the emulator for finger print 1b. Redirect to extended controls, Here click on fingerprint 

setting up the test enviroment 2b

c. Click on Touch Sensor two times. 

setting up the test enviroment 3c

d. Click on done, Now your emulator is ready for Fingerprint testing. 

How to automate Biometric Appium Tests?

Including Biometric Appium tests means we need to be keenly aware of the test infrastructure used to simulate fingerprint actions locally against emulators

Appium tests are performed from a server to which the devices are joined. It provides a context whereby we can insert device-specific commands against the device, in alliance with the calls through the testing framework itself, to simulate the entire workflow on the device in one script. 

To simplify it, check out the documentation on Biometric Authentication with Appium.

Writing Test Cases

Now, we are designing the basic test cases for Appium fingerprint testing using an emulator. In the above of this document, we have mentioned the setup of an emulator for fingerprints. And for testing, we are using a demo application. So we have designed three basic test cases for the fingerprint testing given below and used python programming language to write code. Please review this article for Appium with Python.

1. Test case to verify the availability of the Biometric authentication feature

In this test case we verify the fingerprint feature available in the emulator. Opening an app with a fingerprint feature using Appium and till now, we have not enabled fingerprint in the device. 

So when we open the app then, it gives and pop for setting up a fingerprint. So we are asserting that pop-up. 

Test Steps are the following: 

  • Launch the app
  • Wait to open the app
  • Verify pop-up for unavailability of fingerprint
  • Verify another pop-up for the same

Code Snippet:

import time
from appium import webdriver
# Desire capabilities for device and app
desired_caps = {
'platformName': 'Android',
'platformVersion': '9',
'deviceName': "Pixel3XL",
'udid': 'emulator-5554',
'appPackage': 'com.pro100svitlo.fingerprintauthdemo',
'appActivity': 'com.pro100svitlo.fingerprintauthdemo.MainActivity'
}
# method for test steps 
def verify_the_availability_of_the_biometric_authentication():
#initiate driver with given capabilities
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) 
time.sleep(2)
# assert for authentication availability
assert driver.find_element_by_xpath('//*[@text="Please verify that at least one fingerprint has been registered on the devices"]')\
.is_displayed() == True
assert driver.find_element_by_xpath('//*[@text="Attention"]').is_displayed() == True, f'Fingerprint is enabled'
driver.close()

Test case to verify the availability of the Biometric authentication feature

2. Test case to verify the successful authentication using Biometrics

In this test case, verifying successful authentication using fingerprint.

  • Launch the app
  • send fingerprint id by javascript executor command of appium. (Here sending the id as 1, we set it before in the emulator)
  • verifying redirection of the screen after successful authentication.

Code Snippet:

import time
from appium import webdriver
#desire capabilities for device and app
desired_caps = {
'platformName': 'Android',
'platformVersion': '9',
'deviceName': "Pixel3XL",
'udid': 'emulator-5554',
'appPackage': 'com.pro100svitlo.fingerprintauthdemo',
'appActivity': 'com.pro100svitlo.fingerprintauthdemo.MainActivity'
}

def verify_biometric_authentication_successful():
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
time.sleep(2)
driver.execute_script("adb -e emu finger touch 1")
assert driver.find_element_by_xpath('//*[@text="GO TO MAIN ACTIVITY"]').is_displayed() == True, f'Fingerprint Authentication is not success'
driver.close()

Test case to verify the successful authentication using Biometrics 2Test case to verify the successful authentication using Biometrics 1

3. Test case to verify the Unsuccessful authentication using incorrect Biometrics

In this test case, verifying successful authentication using fingerprint.

  • Launch the app
  • send the wrong fingerprint id by the javascript executor command of Appium.
  • verify the wrong fingerprint pop-up.
  • verifying the app is not redirected to the next screen.
  • send the wrong fingerprint many times and verify the retry text.

Code Snippet:

import time
from appium import webdriver

desired_caps = {
'platformName': 'Android',
'platformVersion': '9',
'deviceName': "Pixel3XL",
'udid': 'emulator-5554',
'appPackage': 'com.pro100svitlo.fingerprintauthdemo',
'appActivity': 'com.pro100svitlo.fingerprintauthdemo.MainActivity'
}

def verify_biometric_authentication_successful():
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
time.sleep(2)
driver.execute_script("adb -e emu finger touch 2")
assert driver.find_element_by_xpath('//*[@text="GO TO MAIN ACTIVITY"]').is_displayed() == False, f'Fingerprint Authentication is success'
driver.execute_script("adb -e emu finger touch 2")
driver.execute_script("adb -e emu finger touch 2")
driver.execute_script("adb -e emu finger touch 2")
assert driver.find_element_by_xpath('//*[@text="Can retry in 01:30"]').is_displayed() == True, f'Fingerprint Authentication is success'
driver.close()

Test case to verify the unsuccessful authentication using incorrect Biometrics 1Test case to verify the unsuccessful authentication using incorrect Biometrics 2

Conclusion

In this article, we described how to test Biometric authentication using Appium. This article was created with a specific tech stack, but we can use many times of tech stacks in fingerprint authentication testing. BrowserStack App Automate enables you to test native and hybrid mobile applications using the Appium automation framework on thousands of real Android and iOS devices.

Try Appium Testing on Real Device Cloud

Also, refer to the following Appium tutorials for Android and iOS devices:

Tags
Automation Testing Parallel Testing

Featured Articles

How to run Appium Tests on macOS?

XPath in Appium: Tutorial

App & Browser Testing Made Easy

Seamlessly test across 20,000+ real devices with BrowserStack