Image injection overview

Different mobile applications employ the built-in device camera to "look" at the outside world and perform different operations based on the image that the camera records. Examples of this would be a barcode-reader application or a bank check scanning application.

To mimic camera behavior when testing these apps using a Perfecto device, you need to provide the application with an image that mocks the use of the camera. Image injection takes an image that is stored on the local machine or in the Perfecto repository and presents it to the application as if it was read by the device camera. This allows you to test the application actions for different types of focus, image placement, and so on. For example, injecting GIFs can help evaluate the robustness of facial recognition and anti-spoofing mechanisms in liveness checks for banking apps.

Image injection requirements

Image injection supports files that meet the following requirements:

  • Max size: 150 MB

  • Format:.jpeg, .jpg, .png, .bmp, .gif

  • Location: Local machine (manual testing and Scriptless Mobile testing only) or Perfecto repository (mandatory for automation testing)

For automation testing, an application identifier is required: BundleID for iOS or PackageName for Android.

Image injection limitations

Code samples

For an Appium code sample that installs a simple camera application, after applying sensor instrumentation, and then injects a .jpg image, see the Community-Samples folder of the PerfectoCode Git repository: https://github.com/PerfectoCode/Community-Samples/tree/master/ImageInjection/JavaSample/MobileSimpleTest

Supported APIs

Image injection is supported for apps using specific Apple/Google APIs. The feature may not work as expected if the app uses SDK functions that are not listed in this section. The same applies for apps that rely on 3rd party frameworks rather than directly on the SDK. We do not officially support any 3rd party SDK because the SDK implementation may change from time to time and utilize unsupported APIs. Furthermore, in some cases, 3rd party SDKs contain logic that relies on the states of phone sensors other than the camera. 

iOS APIs

Function Description

captureStillImageAsynchronouslyFromConnection()

Initiates a still image capture and returns immediately

jpegStillImageNSDataRepresentation()

Returns an NSData representation of a still image and metadata in a JPEG sample buffer

captureOutput()

Notifies the delegate that a new video frame was written

AVMetadataMachineReadableCodeObject

Concrete subclass of AVMetadataObject defining the features of a detected barcode.

Android libraries

Perfecto supports the following Android libraries:

Where to go from here?

To perform image injection, check out the following articles: