How to automate camera pinch to zoom functionality on Android, iOS and Windows?

Can we automate camera pinch to zoom functionality on Android, iOS and Windows?
I need to automate pinch to zoom and verify if the camera preview has been zoomed or not. Is this possible?

hi @ruvindra.senevirathn
I think you can utilize the double tap to zoom the image.

But if your goal is to use pinch, maybe you can use tap and hold

Mobile.tapAndHoldAtPosition(200, 400, 10)

more details : [Mobile] Tap And Hold At Position | Katalon Docs

Structured approach for implementation and verification:


1. Automating Pinch-to-Zoom

Android & iOS (Katalon Studio Mobile):

Use the Mobile.pinch() method with a Test Object representing the camera viewfinder area:

groovy

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

// Define camera preview as a Test Object (adjust locator)
TestObject cameraPreview = findTestObject('camera_viewfinder')

// Pinch-to-Zoom IN (expand fingers)
Mobile.pinch(cameraPreview, 20, 50) // Start at 20% width, end at 50% width

// Pinch-to-Zoom OUT (pinch fingers)
Mobile.pinch(cameraPreview, 50, 20)

Windows (Desktop App):

  • Use mouse wheel or keyboard shortcuts (if supported):

groovy

import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import org.openqa.selenium.Keys as Keys

// Zoom via CTRL + Mouse Wheel
Windows.mouseWheel(cameraObject, 5) // Positive = zoom in
Windows.mouseWheel(cameraObject, -5) // Negative = zoom out

// Or via keyboard shortcuts
Windows.sendKeys(cameraObject, Keys.chord(Keys.CONTROL, Keys.ADD)) // Zoom in
Windows.sendKeys(cameraObject, Keys.chord(Keys.CONTROL, Keys.SUBTRACT)) // Zoom out
  • For touch-enabled Windows devices, use Appium’s TouchAction with multi-touch (complex, requires custom scripting).

2. Verification Strategies

Verify zoom state using these approaches:

a) On-Screen Zoom Indicator (Recommended)

Capture text from the zoom indicator (e.g., “2x”, “200%”):

groovy

// Check Android/iOS
String zoomLevel = Mobile.getText(findTestObject('zoom_indicator'), 10)
assert Integer.parseInt(zoomLevel.replace('x', '')) > 1

// Windows OCR (if text-based)
String indicatorText = Windows.getText(zoomIndicatorObject)
assert indicatorText.contains("200%")

b) Visual Validation (Advanced)

  • Option 1: Use Katalon’s Image-Based Testing:

groovy

// Capture reference image at 1x zoom
WebUI.takeScreenshot('ref_1x.png')

// Capture image after zoom
WebUI.takeScreenshot('after_zoom.png')

// Compare similarity (threshold adjustable)
CustomKeywords.'com.katalon.plugin.imagecomparison.ImageComparator.compareImages'(
  'ref_1x.png', 
  'after_zoom.png', 
  'diff.png', 
  0.9 // 90% similarity threshold
)
  • Option 2: Use optical character recognition (OCR) to detect changes in text size (e.g., a timestamp overlay).

c) API/Log Checks (If Available)

Query device logs or app internals for zoom level changes:

groovy

// Example for Android ADB
String logs = Mobile.callTestCase(
  'adb shell dumpsys media.camera', 
  [:] // Parameters
)
assert logs.contains("zoom=2.0")

d) Element Property Changes

Check if UI elements resize (e.g., a focus reticle):

groovy

int originalWidth = Mobile.getElementWidth(reticalObject)
// Perform zoom...
int newWidth = Mobile.getElementWidth(reticalObject)
assert newWidth > originalWidth

Key Challenges & Workarounds

Platform Challenge Workaround
Android/iOS Camera permissions/OS restrictions Use emulators with open-source camera apps (e.g., Open Camera).
Windows Lack of touch gestures in automation Simulate via mouse wheel or keyboard shortcuts.
Verification No UI indicator Use screenshot comparison or OCR.
Fragility Flaky gesture recognition Add retries and dynamic wait times.

Best Practices

  1. Use Real Devices/Emulators: Enable developer options and disable animations.
  2. Camera App Selection: Test with apps that expose zoom controls (e.g., Open Camera for Android).
  3. Coordinate-Based Fallback: If object-based gestures fail, use absolute screen coordinates:

groovy

// Pinch from (x1,y1) to (x2,y2) on screen
Mobile.pinch(20, 50) // Start 20% from top, end 50%
  1. Error Handling: Wrap actions in try/catch with retry mechanisms.

Conclusion

  • Yes, pinch-to-zoom can be automated on Android/iOS via Mobile.pinch() and on Windows via mouse/keyboard emulation.
  • Verification is achievable through:
    • Zoom indicator text checks (most reliable),
    • Image comparison,
    • OCR, or
    • Element property changes.