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.
- π₯ Inject custom video feeds into Chrome browsers during testing
- π Dynamically change camera sources during test execution
- π Automatic video directory management
- π§ͺ Perfect for testing camera-dependent applications like QR code scanners, video conferencing, etc.
npm install --save-dev wdio-camera-service
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
};
Option | Type | Required | Description |
---|---|---|---|
defaultCameraFeed |
string | β | Path to the default MJPEG video file to use as camera feed |
videoDirectory |
string | β | Directory where session-specific video files will be stored |
- β 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.
SDK | Version | Support? |
---|---|---|
31 | 12 | β |
33 | 13 | β |
34 | 14 | β |
35 | 15 | β |
36 | 16 | β |
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
});
});
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 another video
await browser.changeCameraSource('path/to/face-video.mjpeg');
// Test face detection
await expect($('#face-detected')).toBeDisplayed();
});
});
project/
βββ camera/
β βββ default.mjpeg # Default camera feed
β βββ barcode-sample.mjpeg # Sample barcode video
β βββ face-sample.mjpeg # Sample face video
β βββ video/ # Auto-generated session videos
β βββ 0-0.mjpeg # Session-specific copies
βββ test/
β βββ specs/
β βββ camera.e2e.ts # Test files
βββ wdio.conf.ts # WebdriverIO configuration
- Format: MJPEG (Motion JPEG)
- Extension:
.mjpeg
- Location: Relative to your project root or absolute paths
You can convert existing video files to MJPEG format using FFmpeg:
# Convert MP4 to MJPEG
ffmpeg -i input.mp4 -f mjpeg output.mjpeg
# Convert with specific settings
ffmpeg -i input.mp4 -vcodec mjpeg -q:v 2 -r 30 output.mjpeg
Changes the active camera source to a different video file.
Parameters:
videoFilePath
(string): Path to the new MJPEG video file (relative to project root)
Returns: Promise
Example:
await browser.changeCameraSource('camera/new-feed.mjpeg');
The service will throw errors in the following cases:
- Missing configuration: When
defaultCameraFeed
orvideoDirectory
is not specified - File not found: When the specified video file doesn't exist
- Unsupported browser: When used with non-Chrome browsers (logs warning instead of error)
import { browser } from '@wdio/globals';
describe('Camera Application Tests', () => {
it('should scan QR codes', async () => {
await browser.url('https://qr-scanner-app.com');
// Inject QR code video
await browser.changeCameraSource('camera/qr-code.mjpeg');
await $('#start-camera').click();
await expect($('#qr-result')).toHaveText('Expected QR Content');
});
it('should detect faces', async () => {
await browser.url('https://face-detection-app.com');
// Inject face video
await browser.changeCameraSource('camera/face.mjpeg');
await $('#start-detection').click();
await expect($('#face-count')).toHaveText('1 face detected');
});
});
-
"Default camera feed does not exist"
- Ensure the
defaultCameraFeed
path is correct - Verify the file exists and has proper permissions
- Ensure the
-
"New source camera feed does not exist"
- Check the path passed to
changeCameraSource()
- Ensure the file is in MJPEG format
- Check the path passed to
-
Camera not working in browser
- Verify you're using Chrome/Chromium
- Check browser console for permission errors
- Ensure the test site allows camera access
- Set
logLevel: 'debug'
in your WebdriverIO config to see detailed logs - Check the
videoDirectory
for generated session files - Verify MJPEG files play correctly in media players
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
MIT Licenseβsee LICENSE file for details