Media 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 media that mocks the use of the camera. Media injection takes media that is stored on the local machine or in the Perfecto repository and presents it to the application or mobile browser as if it was read by the device camera. This allows you to test the application or mobile browser actions for different types of focus, media 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:
Media injection requirements
Media injection supports files that meet the following requirements:
-
Max size:
-
iOS and Android apps
-
150 MB (
.jpeg,.jpg,.png,.bmp,.gif)
-
50 MB (
.mp4)
-
-
iOS (Safari) and Android (Chrome) mobile browsers
-
15 MB (
.jpeg,.jpg,.png,.bmp,.gif) -
50 MB (
.mp4)
-
-
-
Format:
.jpeg,.jpg,.png,.bmp,.gif,.mp4.mp4media injection is only supported via Inject media with Appium and Image injection commands. -
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.
Media injection limitations
-
Unique application name: Media injection fails if multiple applications on the device share the same application name.
API support limitations:
- AVCaptureVideoPreviewLayer: Used by the application to display the preview view of the camera. The injected media is displayed only after the camera takes the picture, not during the preview display.
- AVCapturePhotoCaptureDelegate: Media 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 media injectprior to activating the camera.
Functional limitations:
- Separate invocation per camera-based screen: When the application offers different view options for media display, Start media inject should be invoked separately when switching between different screens that use the camera, even if the same media needs to be injected.
- Single instrumented app per device at a time: Media injection is supported only for a single application that is instrumented for the media 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:
- Single active media injection session at a time: Apps that store the media to a private location or to FileProvider locations are not supported. Perfecto only supports media injection for apps that activate the
AndroidMediaStore.ACTION_IMAGE_CAPTUREintent and store the media only to a public URL.
Functional limitations:
- Single active application per media injection session: When testing multiple applications, close the application that started media injection prior to starting media injection for a second application.
-
Animated GIF images:
-
Only supported on Android devices with Camera2 or CameraX.
-
Only supported 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
Media 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 media injection, check out the following articles:
-
Manual testing: Inject image
-
Scriptless testing: Inject an image
-
Automation testing: Inject media with Appium
Perfecto extensions: