How to Test Image Upload Functionality

Posted Jun 10, 2020

Sauce Labs Rubiks Cube

In today’s online world, every digital experience is a reflection of your brand—which is why mobile application testing should be at the forefront of your testing strategy. 

Whether it’s a picture of a check, a selfie, or a QR code, images can be uploaded to mobile apps for many reasons. Behind the scenes, the application has to do some amount of processing and storage. While creating those images might have been as simple as pointing and clicking for the user, testing image uploads themselves can be more challenging.

Before we dive into how to test image upload functionality, let’s quickly look at some common scenarios that require this type of testing.

Common Use Cases

  • Scanning a check for a banking application - A common use case in the financial services industry is mobile check deposit. This is where banks allow customers to deposit checks directly from their mobile device.  

an image of a scanned check from a banking application.

  • Scanning a QR Code - Nowadays, QR codes are often used as a way to bridge print media to digital. Scanning a QR code allows the user to easily navigate to an embedded URL.

Scannable QR code

  • Taking a user profile picture - This could be taking a selfie or uploading a picture for apps that require a user profile photo. This may require a certain file format or size.

Sample profile picture

  • Taking a picture and storing it in a gallery app - Whether it’s a social media app or photo sharing, this use case can span many different types. In its simplest form, it could be taking pictures from the front or back cameras.

Sample image gallery

Regardless of the application, in order to ensure end users have a delightful experience, development teams need to have the ability to use the device camera for taking pictures so they can complete all testing scenarios. If you’re using a cloud service for mobile app testing, the devices will need to offer some type of Camera Image Injection feature.

What is Camera Image Injection?

Camera image injection gives developers the ability to inject images in their automation testing, so that specific test cases such as apps requiring scanning of QR codes or image scanners, can run on a cloud-based testing service as if it were on an actual device. This essentially provides the application with an image that mocks the use of the device camera. 

Testing on Sauce Labs Real Device Cloud

To mimic camera behavior when testing applications on the Real Device Cloud, you need to provide the application with an image that mocks the use of the camera. Sauce enables this with the Camera Image Injection feature. Image injection takes an image (in either .jpeg, or .jpg format) that is stored locally and presents it to the application as if it was read by the device camera. Users can easily test this functionality manually via live testing or insert into their Appium test automation.

Live Testing

In this short video, you can see the uploaded image is used in the app as if the image was taken by the device camera.

image-injection

Appium Test Automation

In your automated test script, you'll need to input the desired capabilities specific to Camera Image Injection (see example code snippets here) and incorporate the uploading of the images and opening of the camera.

  1. Start image injection by adding camera instrumentation desired capability command in your test script. Image injection is enabled by the desired capability sauceLabsImageInjectionEnabled.

  2. When you reach the stage in your test session where you’d like to take an image with the app camera, add the image injection method in your test script. 

  3. After inputting this code, the application reads the image when it captures a photo. You can change the image by sending the custom command with a different image.

For further instructions on how to setup image injection in your account, check out our documentation. Or if you’re new to Sauce Labs and you have an application that requires testing image upload functionality, sign up for our free trial today and you can begin testing in minutes.

Written by

Heather Wellington