QR code and barcode simulation

You can simulate the scanning of QR codes and barcodes to test apps that use QR codes or barcode scanning.

Prepare for QR code and barcode simulation

To simulate QR code and barcode scanning, you specify the image to use instead of the actual scan of the device. You can then use these images to test your app.

When you perform simulation of a QR code, the code scanned by the camera is replaced with the selected file.

To prepare for simulation, create a packaged version of the app that utilizes QR or barcode scanning. For details on how to package an app, see App packaging and signing services. The packaged app must be uploaded to the lab. For details, see Manage apps.

Performing QR code and barcode simulation

The QR code and barcode simulation is available from the Device access window for exploratory testing, and from the UFT One/UFT Developer testing tools.

Note: Simulation is supported only for packaged iOS and Android apps. iOS version should be 12 or higher. The apps need to be uploaded to Digital Lab.

  1. Activate simulation mode, by clicking the QR code and barcode simulation button Simulate QR code or barcode.

    The Simulate QR Code or barcode scan dialog box opens.

  2. Provide files for simulation, one at a time, in one of the following ways:

    1. Paste in the URL of the image or video file.
    2. Browse for a file on a local or network machine.
    3. Drag and drop a file( not supported for UFT One).
  3. Click the uploaded image to select it. A green checkmark indicates this is the image to be used for simulation.
    You can add all your QR code or barcode image files at this stage, even if you do not intend to use them for the current test. See Guidelines for information on the valid file types and sizes. If you have uploaded multiple files, select the image to use the next time your device scans a code by clicking it.

    Tip: If you do not change your selection, the test continues to use the same image each time you scan a code.

  1. Close the dialog box by clicking the close button in the top right hand corner.
  2. On your device, go to the screen in the app from which you are scanning the code. Click the Simulation button Simulate QR code or barcode and click SCAN.
  3. When simulating multiple scans, for each code simulation click the Simulation button Simulate QR code or barcode, select the image to use, and click SCAN.

Back to top

Guidelines for QR code and barcode simulation

When using QR code and barcode simulation for replacing images, follow these guidelines.

General guidelines

The following table details some general guidelines to be followed when using QR code and barcode simulation:

Image Make sure that the QR code you are simulating is clear, centered, and not bent.
Placement of image

Make sure that the bar code is clear and is in a place that can be detected by the barcode detection area. (The detection area is determined by the app.) If your simulation fails during replay, open the captured image and check the location of the bar code. Make sure that the barcode is near the center of the barcode detection area. If it is not, either crop the existing image or create a new image with a light background with just the barcode in the center.

Barcode detected Barcode not detected
Barcode detected successfully Difficulty in detecting barcode
Supported formats The supported image formats are: JPG, GIF, PNG, BMP, and WBMP.
For Android camera 2, only JPG and YUV_420_888 image formats are supported.
Record and replay

Recording of QR codes and bar codes is not supported for testing tools, including UFT One, Sprinter; replay is supported.

To replay on iOS or Android, add the SimulateBarcodeByImage method. For example:

Example:
Device("Device").UploadMedia "CODE39.png", "Z:\QRCode_Image\Scandit_Demo\PNG_File\CODE39.png"

Device("Device").App("SimpleSample").SimulateBarcodeByImage "CODE39.png"

On iOS, you can also use the SimulateBarcodeByData method. For example:

Example:
Device("Device").App("com.ot.ScanditSample").SimulateBarcodeByData "OK","AZTEC"

Exploratory testing When working in the remote device view with exploratory testing, simulation cannot be deactivated after it has been activated.
File size

The maximum upload file size for images is 5 MB. The maximum upload size for videos is 20 MB with 1.5 GB of free memory for Android devices, and 40 MB for iOS devices.

Uploaded files

The uploaded files are only valid for the current session. After the test or remote view session is finished, the files are erased.

Back to top

Android specific

  • Android X: Photo and barcode simulation can only be used one at a time. If your app uses both photo and barcode simulation, deactivate one before activating the other. For automation, ensure that you use a stop operation before switching between simulations.

  • When working with Android 6.0 or later, you must have permission to access the device's external storage.
  • Simulation is only supported for Scandit Barcode Scanner SDK, Google Mobile Vision, ML Kit, ZXing and other barcode recognition tools based on an image captured by camera 1, camera 2, and camera X. The native camera API  is not supported.
  • This simulation is only supported for apps using the YUV NV21 camera preview image format.
  • Simulation may not be possible if you customized the built-in camera settings.
  • Set the saveToPic parameter to true (false by default) to save the image to a subfolder in the device's photo gallery. For example, modify the recorded step:

    Device("Device").UploadMedia "sample.png","C:\sample.png"

    to

    Device("Device").UploadMedia "sample.png","C:\sample.png",True

Back to top

iOS specific

For iOS, the following are supported:

  • AVFoundation
  • Vision.framework
  • ZXing Objective C library
  • ZXing C++ library

Back to top

See also: