Skip to main content

Camera Image Injection

Camera Image Injection feature allows you to test image capturing, QR code scanning, and barcode scanning functionalities in your app across 3000+ real devices on the LambdaTest Real Device Cloud platform.

This tool is ideal for testing features such as:

  • Scanning QR codes linked to embedded URLs
  • Check scanning
  • Capturing profile photos
  • Uploading images to your app

How It Works

LambdaTest utilizes Sensor Instrumentation to integrate with various mobile sensors, including the camera. When you enable Image Injection for a session, LambdaTest injects its camera code module into your app through Sensor Instrumentation. This module then mocks or overrides the Android or iOS SDK used in your app.

Key Features

  • Compatible with 3000+ real mobile devices
  • Supports image capturing, QR code scanning, and barcode scanning
  • Seamless integration with your existing app testing workflow
note
  • Video capture and other media types are not currently supported.
  • For iOS apps signed with Enterprise Certificates, app resigning (a prerequisite for using the Image Injection tool) is not available.

Supported Camera 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.

Supported APIs
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.

Image Injection in App Automation

This section explains how to use Image Injection with App automation. This section will also teach you how to use image injection for all the possible test cases for your app along with other useful information.

Step 1: Upload image to LambdaTest

You can use the following curl command to upload any image of your choice to the LambdaTest cloud. Please note that we support only JPG, JPEG, and PNG formats which can be 10 MB or less.

curl -u "undefined:undefined" -X POST "https://mobile-mgm.lambdatest.com/mfs/v1.0/media/upload" -F "media_file=@"/Users/macuser/Downloads/image.jpeg"" -F "type="image"" -F "custom_id="SampleImage""

Response of above cURL will be a JSON object containing the media_url of the format - lt://MEDIA123456789123456789 as shown below.

{
"media_url":"lt://MEDIA123456789123456789",
"name":"IMG_123.jpg",
"status":"success",
"custom_id":"SampleImage"
}

Step 2: Enable Image injection in the Appium Session

You can use the appium capability to turn the image injection on in your application. Just add "enableImageInjection": True in the desired capabilities while writing the automation script. By adding this capability the app undergoes Sensor Instrumentation, which was described earlier in the documentation. Also adding media url "media": "lt://MEDIA123456789123456789" in the capabilities to inject the image is now optional and can be passed in LambdaHook as mentioned in step 3.

desired_capabilities = {
"enableImageInjection": True,
"media": "lt://MEDIAf446d4170cd946aa9ec307d10cb679b9", #Add media_url here (optional)
}

Step 3: Inject the image

Refer to the code snippets given below to upload the image with the action ImageInjection. Please make sure that the image needs to be injected before the camera is triggered in your application. This is due to the fact that the camera only captures the image injected at the last.

driver.execute_script("lambda-image-injection=media_url") #Add media_url here
info

Use Case: This feature can be used when you want to test injecting more than one images in single test at different instances. The image injected through above process will replace the image which you put in previous steps.

Step 4: Capture the desired image through camera

You need to first add a logic to inject the uploaded image in the script. Thereafter add the logic to click the camera button in the mobile app. This will show you the last injected image on your mobile app screen.

📕 Check the documentation for Camera Image Injection feature in Manual App Testing on Real devices

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles