MagicPod supports testing camera functionality.
In particular, with the cloud environment, you can preset any image in advance, making it easy to verify operations that were previously difficult to test, such as scanning QR code payments.
Table of contents
Cloud Environment
Using the Set image for camera command, you can run tests with an arbitrary image set on the rear camera of a cloud device. You can specify not only still images but also animated images.
How to use the command
When you take a photo using the app's camera function while an image is set with the "Set Image for Camera" command, the image set by the command will be retrieved.
The image can be replaced any number of times during test execution.
If the app detects information such as QR codes, barcodes, faces, or objects within the image, the detection results are automatically passed to the app.
Limitations
Common to iOS/Android
- You can only set the back camera image. Currently, setting the front camera image is not supported.
- Shooting settings, such as flash and focus, have no effect on the captured image.
- If the target app attempts to take a photo before setting an image with this command, it will not be able to retrieve any photo.
iOS
- Available only on cloud devices running iOS 17 or later.
- Live Photos are not supported.
- Depth-based features, such as Portrait mode, are not supported.
- If your target app is designed to run tests using a camera on the iOS simulator without this feature, enabling the feature may cause the target app to stop working.
Android
-
Available only on Android cloud devices where "Device Type" in the test run settings is set to "Emulator (arm64-v8a)."
- If the input image is too large in terms of dimensions, it will be downscaled to at most 1920×1080. Whether downscaling occurs or not, the input image will then aspect-fit into whatever resolution the app requests. Therefore, an app whose requested aspect ratio differs from your image will see black bars around the image (letterboxing/pillarboxing).
Information for App Developers
iOS
The API names listed below are for Swift. Please refer to Apple's official documentation for the corresponding Objective-C.
The image you set is provided through the standard camera pipeline, so the following all work as if a real camera were returning that image:
-
Photo capture (
AVCapturePhotoOutput) — the set image is returned as the captured photo. -
Live preview (
AVCaptureVideoPreviewLayer) — the set image is shown in the camera preview. -
Video frames (
AVCaptureVideoDataOutput) — the set image is delivered frame by frame. -
Video recording (
AVCaptureMovieFileOutput) — recording produces a movie of the set image. -
Metadata (Barcode, QR code, face detection, etc.) (
AVCaptureMetadataOutput) — the metadata in the set image is detected and reported.
Photo capture flow
For photo capture, the target app must use the following flow:
- The target app must call
capturePhoto(with:delegate:)from theAVCapturePhotoOutputclass and pass a delegate instance.
When capturePhoto(with:delegate:) is called, the cloud device will trigger these delegate methods in order:
-
photoOutput(_:willBeginCaptureFor:)
→ Notifies that the capture is about to begin. -
photoOutput(_:willCapturePhotoFor:)
→ Notifies that the photo is about to be captured. -
photoOutput(_:didFinishProcessingPhoto:error:)
→ Returns the captured (in this case, simulated) photo image. -
photoOutput(_:didFinishCaptureFor:error:)
→ Notifies that the photo capture process has completed.
If the delegate does not implement a method, it will simply be skipped. Other methods outside these will not be called.
To avoid runtime errors, the basic APIs for camera-related classes have been configured to behave safely.
AVCaptureSessionAVCaptureDeviceAVCaptureDeviceInputAVCaptureDeviceDiscoverySessionAVCapturePhotoOutputAVCapturePhotoAVCaptureResolvedPhotoSettingsAVCaptureVideoDataOutputAVCaptureVideoPreviewLayerAVCaptureMetadataOutputAVCaptureMovieFileOutputAVCaptureConnection
If more advanced camera control or customization is required, please contact us.
Android
Any API that receives frames from the device camera receives the set image — CameraX, Camera2, the deprecated Camera API, and libraries built on them such as ML Kit barcode scanning. There is no restricted subset of APIs and no special integration required.
Local PC Environment
In the local PC environment, camera functionality is available. However, unlike the cloud environment, you cannot set an arbitrary image.
External Cloud Service Environment
In external cloud services like SauceLabs, the camera functionality is available. However, unlike the cloud environment, you cannot set an arbitrary image.