"Set image for camera" command
On cloud devices running iOS 17 or later, you can simulate taking a photo by using the "Set image for camera" command.
After this command is executed, whenever the application under test (AUT) takes a photo, the device will return the image you set instead of capturing a real one.
However, depending on how the AUT implements its camera functionality, you may not be able to capture images. For details, please see the "Information for App Developers" below.
This feature is enabled based on whether the test case includes the "Set image for camera" command.
- In case of batch run: Any of the test cases in the batch run includes the "Set image for camera" command, the feature is enabled through the batch run.
- In case of the "Run" button on the test case edit page: The feature is enabled/disabled at the following times. (In other words, even if you add the "Set image for camera" command, the feature is not enabled until the following times):
- When the cloud device is launched.
- When the "Launch app" command is executed with an option other than "(by first-time-only process restart)" selected
Restrictions
When using this feature, please note:
- The image you set is a single still image. It is shown as a steady camera feed (the same frame, continuously) and does not play back as motion video.
- Live Photos are not supported.
- Depth-based features, such as Portrait mode, are not supported.
- Shooting settings, such as flash and focus, have no effect on the captured image.
- If the AUT attempts to take a photo before setting an image with this command, the AUT will not crash, but it will not be able to retrieve any photo.
- If your AUT is designed to run tests using a camera on the iOS simulator without this feature, enabling the feature may cause the AUT to stop working.
Information for App Developers
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 AUT must use the following flow:
- The AUT 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.