Image Injection

The Set Camera Image function allows you to set an image to be used when triggering the camera during a test. For example, you could use this to inject a QR code into your test script.

Compatibility Summary

Service

iOS

Android

Requirements

Device

Simulator

Device

Simulator

On Premises

Not supported

Not supported

Not supported

Supported

Update emulator settings.

Sauce Labs

Supported

Not supported

Supported

Not supported

Add capability: sauceLabsImageInjectionEnabled: true

BrowserStack

Supported

Not supported

Supported

Not supported

Add capability: enableCameraImageInjection: true

LambdaTest

Supported

Not supported

Supported

Not supported

Add capability: enableImageInjection: true

On-Premises

Available for Android emulators only when running AIQ locally.

When running AIQ on an EC2 we don’t have access to JAVA_HOME environmental variable nor the local file system, hence we can’t override the emulator settings.

Android Emulator Setup

  1. From Android Studio open the Device Manager.

  2. Click the Edit button for the emulator that you want to use.

  3. In the Virtual Device Configuration window, click Show Advanced Settings.

  4. In the Camera section select VirtualScene from the drop down.

  5. Click Finish.

Sauce Labs

Available for Android and iOS physical devices only. There’s support for native apps only.

The config file’s capabilities need to include the following field:

"sauceLabsImageInjectionEnabled": "true"

Sauce Labs' App Config

  1. Login into your Sauce Labs account.

  2. Go to App Management.

  3. Click the Settings button for the app you want to use.

  4. Turn the Image Injection switch on.

Supported APIs

Android System Camera

For Android devices, there are multiple ways to capture an image, as described in the Android Camera API developer documentation. AIQ supports the following:

  • ACTION_IMAGE_CAPTURE Opens the system camera and notifies the calling app when the image is taken.

  • camera2 API: Everything is configured and handled from within the app.

  • cameraX: Leverages the capabilities of camera2, but uses a simpler, use case-based approach that is lifecycle-aware.

  • Camera API (deprecated): partially supported. As with camera2, everything is handled in the app itself. QR Code readers often use Camera#setPreviewCallback. We pass the injected image to this method, but the rest of this deprecated API is not supported. UI Elements will not likely display the injected image.

iOS System Camera

For iOS devices, the camera can be configured with different outputs. AIQ supports the following:

  • AVCapturePhotoOutput: for capturing still images. The results are received via the AVCapturePhotoCaptureDelegateand the method captureOutput:didFinishProcessingPhoto:error: The other methods in this delegate are either deprecated or handle live photos, which we don't support.

  • AVCaptureVideoDataOutput: for capturing video frames and processing them. The frames are received via AVCaptureVideoDataOutputSampleBufferDelegate and the method captureOutput:didOutputSampleBuffer:fromConnection:.

  • AVCaptureMetadataOutputfor reading QR-Codes. The QR Codes are passed to the app via captureOutput:didOutputMetadataObjects:fromConnection:. We are detecting the AVMetadataMachineReadableCodeObject and QR Codes are part of that.

Sauce Labs documentation is available here.

BrowserStack

The config file’s capabilities need to include the following field:

"browserstack.enableCameraImageInjection": "true"

Supported APIs

Camera image injection is supported for the following Camera APIs. Check with your app development team to get more details about the Camera APIs your app uses.

OS

OS version

Supported APIs

iOS

iOS 13 and above

didFinishPickingMediaWithInfo API of UIImagePickerController iOS SDK class for capturing an image. For more details, please check Apple documentation.

AVCapturePhoto iOS SDK class for receiving captured photos from AVCapturePhotoOutput API. For more details, please check Apple Documentation.

jpegStillImageNSDataRepresentation of AVCaptureStillImageOutput iOS SDK class. For more details, please check Apple documentation.

Android

Android 6 and above

android.hardware.camera.PreviewCallback API for API level 1-20

android.hardware.camera2.CameraManager, android.hardware.camera2.CameraDevice, android.hardware.camera2.CameraCharacteristics, android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.media.ImageReader APIs for API level >=21

Camera Intent API

Browser Stack full documentation here.

LambdaTest

The config file’s capabilities need to include the following field:

"enableImageInjection": "true"

LambdaTest App Setup

1. Login to your LambdaTest account.

2. Go to App Testing under Real Devices.

3. Hover the Settings icon and toggle the Image Injection switch on.

image-20240624-134834.png

Supported APIs

Below given is the list of Camera APIs which are supported by LambdaTest Image Injection tool. Please ensure that your app uses these APIs only to enable Image Injection.

OS

Devices

Supported APIs

iOS

iOS 13 and higher

didFinishPickingMediaWithInfo API of UIImagePickerController iOS SDK class for capturing an image. For details, please check Apple documentation.

AVCapturePhoto iOS SDK class for receiving captured photos from AVCapturePhotoOutput API. For details, please check Apple Documentation.

Android

Android 9 and higher

CameraX API is used. For details, please check CameraX Documentation

Camera API is used. For details, please check this link.

Camera2 API is used. For details, please check this link.

ACTION_IMAGE_CAPTURE is standard Intent action that can be sent to have the camera application capture an image and return it. For details please check this link.

LambdaTest full documentation here.