Image Injection

You are here:
< All Topics

Overview:

Image injection is a technique that allows you to test applications that use the device camera by providing them with an image that simulates the camera input. It is used to verify the app’s functionality and behavior based on the injected image. Image injection can help you test your app’s camera features faster, easier, and more reliably.

 

Step 1: Log in to the TestGrid portal with valid credentials.

  • Start by logging in with valid credentials and navigating to the “Real Device Cloud” option tab.
  • After selecting the “Connect” button for a specific device, the user will encounter the device screen interface, which showcases a range of options.
  • Click the installation button on the device. Tap Image Injection to upload the IPA/APK file. After successfully uploading the IPA/APK file, click the “Upload Image” option for the desired image.
  • Click on “Upload Image.” Once the upload image process is complete, you will see a success message; then, click the install button.

 

 

 

 

Step 2: Once the installation is complete, you will see the app installation successfully message on the right top of the screen; then, click on the “Choose Image” text.

 

 

Step 3: After clicking the Choose Image text, the camera screen on the device will open. Click on the OK button to take a picture before pressing the camera button.

 

 

 

Step 4: After taking a picture, you will see the image and on the bottom side, you will see the photo text Click on this.

 

 

 

Step 5: Select “Use photo” from the screen to view the uploaded image rather than taking a new one.

 

 

 

 

Step 6: How to Automate Camera Image Injection with Automation.

You can use TestGrid to test image capture and QR/bar code reading from the camera on a TestGrid mobile device. If your mobile app includes features like check scanning, profile image capture, and QR/Bar code scanning, you can use this feature to automate testing of those features.

What you will discover in this guide is:

1. How TestGrid enables camera testing:

TestGrid uses sensor instrumentation to make it easier for an application to communicate with a variety of mobile sensors, such as the camera and biometric authentication. If Camera Image Injection is enabled for the session, the procedure of injecting the TestGrid Camera code module into the app is known as sensor instrumentation. This code module simulates or overrides the iOS SDK or Android SDK Camera APIs that are used by the application.

2. During a Local Appium Code execution session, test camera image capture:

Take a look at this screenshot of a banking app that can take pictures of the front and back of a real check: Taking a picture of a physical check and depositing it is a common use case found in contemporary banking systems. To test this use case, upload the image to our cloud, enable Appium, and then inject it right before the script’s click camera button event.

Examining the image captured by the camera includes:

2.1. Discover the devices and APIs that are supported:

Camera image injection is supported for the following camera APIs: Check with your app development team for further information on the camera APIs that your app uses.

OS

OS version

Supported APIs

    iOS

iOS 13 and above

finishPickingMediaWithInfoAPI of theUIImagePickerController iOS SDK class for capturing an image.

AVCapturePhoto is aniOS SDK class for receiving captured photos from the AVCapturePhotoOutput API.

jpegStillImageNSDataRepresentationof theAVCaptureStillImageOutput iOS SDK class.

 

2.2. Upload the desired image to TestGrid:

Use the following cURL command to upload your selected image to TestGrid. JPG, JPEG, and PNG picture formats are supported, and the maximum file size allowed is 1 MB.

curl –location ‘https://publicdev.testgrid.io/api/image-integration?user_token=ochskrxwei4ujverxb8w5jfxj1bgnlsw’ \
–header ‘Cookie: ci_session=e37dcuknco44afmlrd5tlacv1kdqb1e7’ \
–form ‘image=@”/Users/imac/Downloads/check-icon.png”‘

 

The following image shows the sample response, which includes the media ID to be set in  image_url used later in the test script.

{ “success”: true, “id”: “656f200792204” }

2.3. Enable Camera Image Injection in the Appium session:

Enable Camera Image Injection to ensure your app goes through Sensor Instrumentation, a method that allows TestGrid to enable an app’s interaction with various mobile sensors, such as cameras or biometric authentication.

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(“tg:enableCameraInjection”, “true”);

2.4. Inject the uploaded image before the camera is triggered in the app:

((JavascriptExecutor)driver).executeScript(“tg:cameraInjection”,
ImmutableMap.of(“ImageId”, “654f6286d0cdf”));

2.5. Trigger the camera in the app and take a photo:

After adding the logic to inject the uploaded image, add the logic to click the Camera button in the mobile app. The most recently injected image will be replaced by the image caught by the camera.

 

Happy Testing!

 

Table of Contents