Camera Service Service
wdio-camera-service is a 3rd party package, for more information please see GitHub | npm
A WebdriverIO service that enables camera feed injection for testing applications that use camera/video inputs. This service allows you to mock camera feeds with pre-recorded video files during automated testing.
Features
- 🎥 Inject custom video feeds into Chrome browsers during testing
- 🔄 Dynamically change camera sources during test execution
- 📁 Automatic video directory management
- 🔄 Automatic format conversion - Use MP4, WebM, PNG, JPG and more (requires FFmpeg)
- 💾 Smart caching - Converted files are cached to avoid re-conversion
- 🧪 Perfect for testing camera-dependent applications like QR code scanners, video conferencing, etc.
Installation
npm install --save-dev wdio-camera-service
Configuration
Add the camera service to your WebdriverIO configuration:
// wdio.conf.ts
export const config: WebdriverIO.Config = {
// ... other config
services: [
['camera', {
defaultCameraFeed: './camera/default.mjpeg',
videoDirectory: './camera/video',
}],
],
// ... other config
};
Service Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
defaultCameraFeed | string | ✅ | - | Path to the default video file |
videoDirectory | string | ✅ | - | Directory for session-specific video files |
ffmpegPath | string | ❌ | 'ffmpeg' | Custom path to FFmpeg executable |
cacheEnabled | boolean | ❌ | true | Enable caching of converted files |
outputFormat | 'mjpeg' | 'y4m' | ❌ | 'mjpeg' | Output format for converted files |
Supported Formats
The service supports multiple input formats with automatic conversion:
Native Formats (No Conversion)
.mjpeg- Motion JPEG.y4m- YUV4MPEG2
Video Formats (Requires FFmpeg)
.mp4- MPEG-4 Video.webm- WebM Video.avi- AVI Video.mov- QuickTime Video.gif- GIF (animated or static)
Image Formats (Requires FFmpeg)
Images are converted to a single-frame MJPEG (Chrome loops it automatically):
.png- PNG Image.jpg/.jpeg- JPEG Image.bmp- Bitmap Image
FFmpeg Requirement
FFmpeg is only required when using non-native formats (MP4, WebM, PNG, etc.).
If you only use .mjpeg or .y4m files, FFmpeg is not needed.
Installing FFmpeg
macOS:
brew install ffmpeg
Ubuntu/Debian:
sudo apt-get install ffmpeg
Windows:
winget install FFmpeg
# or
choco install ffmpeg
Or download from: ffmpeg.org
Browser Support
- ✅ Chrome/Chromium/Android Chrome - Full support
- ❌ Firefox - Not supported
- ❌ Safari - Not supported
- ❌ Edge - Not supported (unless Chromium-based)
Note: This service only works with Chrome/Chromium browsers as it relies on Chrome-specific command line arguments for camera mocking.
Android SDK Supports (With Chrome)
| SDK | Version | Support? |
|---|---|---|
| 31 | 12 | ✅ |
| 33 | 13 | ✅ |
| 34 | 14 | ✅ |
| 35 | 15 | ✅ |
| 36 | 16 | ✅ |
Usage
Basic Usage
The service automatically injects the default camera feed when the browser starts:
describe('Camera Tests', () => {
it('should use default camera feed', async () => {
await browser.url('https://example.com/camera-app');
// Your default camera feed is now active
});
});
Using Different Formats
You can use various formats as your default camera feed:
// wdio.conf.ts
export const config: WebdriverIO.Config = {
services: [
['camera', {
// Use a PNG image as the default feed (Chrome loops it automatically)
defaultCameraFeed: './camera/qr-code.png',
videoDirectory: './camera/video',
}],
],
};
Changing Camera Source
Use the changeCameraSource command to switch video feeds during test execution:
describe('Camera Tests', () => {
it('should change camera source dynamically', async () => {
await browser.url('https://example.com/camera-app');
// Start with default feed, then switch to a different video
await browser.changeCameraSource('path/to/barcode-video.mjpeg');
// Test barcode scanning functionality
await expect($('#barcode-result')).toHaveText('123456789');
// Switch to a PNG image (automatically converted to video)
await browser.changeCameraSource('path/to/qr-code.png');
// Test QR code scanning
await expect($('#qr-result')).toHaveText('QR Content');
});
});
File Structure
project/
├── camera/
│ ├── default.mjpeg # Default camera feed (MJPEG)
│ ├── qr-code.png # QR code image (auto-converted)
│ ├── barcode-sample.mp4 # Barcode video (auto-converted)
│ └── video/ # Auto-generated session videos
│ ├── 0-0.mjpeg # Session-specific copies
│ └── .cache/ # Cached converted files
│ └── abc123.mjpeg # Hash-based cache
├── test/
│ └── specs/
│ └── camera.e2e.ts # Test files
└── wdio.conf.ts # WebdriverIO configuration
Video File Requirements
Native Format (Recommended)
- Format: MJPEG (Motion JPEG) or Y4M
- Extension:
.mjpegor.y4m - Location: Relative to your project root or absolute paths
Other Formats
When using non-native formats, the service will automatically convert them using FFmpeg.
Converted files are cached in videoDirectory/.cache/ to avoid repeated conversions.
Creating MJPEG Files Manually
You can convert existing video files to MJPEG format using FFmpeg:
# Convert MP4 to MJPEG
ffmpeg -i input.mp4 -q:v 2 output.mjpeg
# Convert image to single-frame MJPEG
ffmpeg -i input.png -frames:v 1 -q:v 2 output.mjpeg