For AI agents and LLMs: a machine-readable index is available at llms.txt. A plain-Markdown version of any documentation page is available by appending .md to its URL.
Skip to main content

How to Inject a Mock Video Stream in Selenium on TestMu AI


Inject a custom video file as a fake camera feed in Chromium-based Selenium tests on TestMu AI. This is useful for testing WebRTC, video conferencing, KYC or identity verification, and any flow that calls getUserMedia().

How It Works​


Upload a video file, pre-load it onto the test VM, and pass Chrome flags to use it as a fake camera device.

  1. Upload your .mjpeg or .y4m video file to TestMu AI using the web automation user-files API.
  2. Pre-load the file onto the test VM using the lambda:userFiles capability.
  3. Pass Chrome flags to use the uploaded file as a fake camera device.

Chrome treats the file as a looping camera feed, so any getUserMedia({ video: true }) call receives frames from your file instead of a real camera. If you are new to the platform, first run your first Selenium test to confirm your setup before layering on video injection.

Prerequisites​


Verify the following before configuring mock video injection.

  1. Get a TestMu AI account with Web Automation access, and find your credentials on the TestMu AI Dashboard.
  2. Prepare a .mjpeg video file such as sample_640x360.mjpeg (recommended resolution: 640x360 or 1280x720; Chrome also supports .y4m format).
  3. Set TestMu AI credentials as LT_USERNAME and LT_ACCESS_KEY.

Step 1: Upload the Video File​


Upload your .mjpeg file using the web automation user-files API.

cURL​


Verified
curl -X POST \
"https://api.lambdatest.com/automation/api/v1/user-files" \
-u "$LT_USERNAME:$LT_ACCESS_KEY" \
-F "files=@/path/to/sample_640x360.mjpeg"

Response​


Verified
{
"status": "success",
"data": [
{
"error": "",
"message": "File have been uploaded successfully to our lambda storage",
"key": "sample_640x360.mjpeg"
}
]
}
note

Limits: maximum 20 MB per upload and maximum 150 files per organization.

The /mfs/v1.0/media/upload endpoint is for mobile and app automation. For web automation, use /automation/api/v1/user-files.

Step 2: Configure Selenium Capabilities​


Add the video file and Chrome flags to your Selenium capabilities configuration. For the complete reference of options you can set here, see the Selenium automation capabilities.

Java (Selenium 4, W3C)​


Verified
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.*;

ChromeOptions options = new ChromeOptions();

options.addArguments(
"--use-fake-ui-for-media-stream",
"--use-fake-device-for-media-stream",
"--use-file-for-fake-video-capture=/home/ltuser/Downloads/sample_640x360.mjpeg"
);

HashSet<String> userFiles = new HashSet<>();
userFiles.add("sample_640x360.mjpeg");

HashMap<String, Object> ltOptions = new HashMap<>();
ltOptions.put("platform", "Linux");
ltOptions.put("build", "Mock Video Injection Test");
ltOptions.put("name", "Fake Camera Feed Test");
ltOptions.put("video", true);
ltOptions.put("w3c", true);

options.setCapability("LT:Options", ltOptions);
options.setCapability("lambda:userFiles", userFiles);

RemoteWebDriver driver = new RemoteWebDriver(
new URL("https://" + LT_USERNAME + ":" + LT_ACCESS_KEY + "@hub.lambdatest.com/wd/hub"),
options
);

Python​


Verified
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--use-fake-device-for-media-stream")
options.add_argument("--use-file-for-fake-video-capture=/home/ltuser/Downloads/sample_640x360.mjpeg")

lt_options = {
"platform": "Linux",
"build": "Mock Video Injection Test",
"name": "Fake Camera Feed Test",
"video": True,
"w3c": True,
}

options.set_capability("LT:Options", lt_options)
options.set_capability("lambda:userFiles", ["sample_640x360.mjpeg"])

driver = webdriver.Remote(
command_executor=f"https://{LT_USERNAME}:{LT_ACCESS_KEY}@hub.lambdatest.com/wd/hub",
options=options,
)

JavaScript (WebDriverIO or Raw WebDriver)​


Verified
const capabilities = {
browserName: "Chrome",
browserVersion: "latest",
platformName: "Linux",
"LT:Options": {
platform: "Linux",
build: "Mock Video Injection Test",
name: "Fake Camera Feed Test",
video: true,
w3c: true,
},
"lambda:userFiles": ["sample_640x360.mjpeg"],
"goog:chromeOptions": {
args: [
"--use-fake-ui-for-media-stream",
"--use-fake-device-for-media-stream",
"--use-file-for-fake-video-capture=/home/ltuser/Downloads/sample_640x360.mjpeg",
"--no-sandbox",
"--disable-gpu",
],
},
};

Step 3: Verify the Video Feed in Your Test​


Navigate to a page that requests camera access and confirm the fake stream is active.

After the session starts, navigate to a page that requests camera access and confirm the fake stream is being used.

Verified
driver.get("https://www.lambdatest.com/selenium-playground/webrtc-video");

// Or open your application's camera page
driver.get("https://your-app.com/video-call");

Boolean isPlaying = (Boolean) driver.executeScript(
"const video = document.querySelector('video');" +
"return video && !video.paused && video.readyState >= 2;"
);

File Paths by OS​


The lambda:userFiles capability places files in these directories.

PlatformFile Path
Linux/home/ltuser/Downloads/sample_640x360.mjpeg
WindowsC:\\Users\\ltuser\\Downloads\\sample_640x360.mjpeg
macOS/Users/ltuser/Downloads/sample_640x360.mjpeg

Adjust the --use-file-for-fake-video-capture path to match your target platform.

Chrome Flags Reference​


The following Chrome flags control fake media device behavior.

FlagPurpose
--use-fake-ui-for-media-streamAuto-grants getUserMedia() permission without a popup
--use-fake-device-for-media-streamReplaces real camera and microphone hardware with fake devices
--use-file-for-fake-video-capture=<path>Uses the specified file as the fake camera feed
--use-file-for-fake-audio-capture=<path>Uses the specified file as fake microphone input (.wav format)

Troubleshooting​


Refer to the following table for common issues and solutions.

IssueSolution
Black or empty video feedVerify the file name in lambda:userFiles matches exactly, including case
Permission popup still appearsConfirm --use-fake-ui-for-media-stream is set
File not found on VMCheck the OS-specific path; if needed, use driver.executeScript("lambda-files-download=sample_640x360.mjpeg") as a fallback
Video not loopingChrome loops .mjpeg files automatically; .y4m files also loop by default
Wrong resolutionUse a file resolution that matches your app expectations; 640x360 is a safe default
Windows path errorsUse escaped backslashes: C:\\Users\\ltuser\\Downloads\\sample_640x360.mjpeg
macOS video does not renderThis is a known Chrome limitation; use Linux when visual verification is required

Next Steps​


Continue with these related guides:

Terminal First Testing With Kane CLI

Natural language browser & mobile app tests right from terminal.

×
Schedule Your Personal Demo
Kane CLI terminal

Help and Support

Related Articles