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.
On this page:
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

-
The application to receive the injected image must have a unique name. If another application with the same name exists, the image injection will fail.

API support limitations:
- AVCaptureVideoPreviewLayer: Used by the application to display the preview view of the camera. The injected image is displayed only after the camera takes the picture, not during the preview display.
- AVCapturePhotoCaptureDelegate: Image injection is not currently supported for applications based on this class.
- AVCaptureMetadataOutput: Used by different bar-code reader applications. When an application uses this API, use
Start image inject
prior to activating the camera.
Functional limitations:
- When the application offers different view options for image display, Start image inject should be invoked separately when switching between different screens that use the camera, even if the same image needs to be injected.
- Image injection is supported only for a single application that is instrumented for the image injection on the device. If an application on the device, other than the currently tested application, is instrumented for injection, uninstall it before testing the current application.

API support limitations:
- Apps that store the image to a private location or to FileProvider locations are not supported. Perfecto only supports image injection for apps that activate the
Android
MediaStore.ACTION_IMAGE_CAPTURE
Intent and store the image only to a public URL.
Functional limitations:
- When testing multiple applications, close the application that started image injection prior to starting image injection for a second application.
-
Animated GIF images are only supported on Android devices with Camera2 or CameraX.
-
Perfecto currently supports GIFs with up to 15 frames. A GIF file that is too large in size may cause a timeout.
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 |
---|---|
|
Initiates a still image capture and returns immediately |
|
Returns an NSData representation of a still image and metadata in a JPEG sample buffer |
|
Notifies the delegate that a new video frame was written |
|
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:
-
Manual testing: Inject an image
-
Scriptless testing: Inject an image
-
Automation testing: Inject an image injection with Appium
Perfecto extensions: