Skip to navigation

Record video automatically

Doc Detective records a video of every context that drives a browser, a native app, or a device, by default and with no record steps. It’s a video archive of every run, and a replay of exactly what happened when a test fails. New to recording? Start with Record video.

Before you begin

Make sure you have the following:

The steps in this guide work the same in every authoring style. Write them in a standalone .spec.json, inline in a doc source file, or let Doc Detective detect them from prose.

What you get by default

With no setting at all, Doc Detective records each context from its first step to its last, with the engine that fits:

ContextHow it’s recorded
Headless Chrome, the default browserThe browser engine records the tab. It needs no display.
Headless Chrome with its own record stepNot recorded automatically. Your record step wins, since a Chrome context records one tab at a time.
Headed Chrome, Firefox, or SafariThe ffmpeg engine records the screen.
Headless FirefoxRuns headed so the ffmpeg engine can record it, when the host can capture the screen. On Linux with Xvfb installed, it runs on an Xvfb display, so no window appears. With only DISPLAY, the window opens on that display. Otherwise it stays headless and isn’t recorded.
A native app on Windows or macOSThe ffmpeg engine records the whole display.
An Android or iOS app, or mobile webThe device records its own screen.
No browser, app, or device stepsNot recorded.

When Doc Detective runs headless Firefox headed, it says so once per run: Running 2 headless Firefox contexts headed so autoRecord can record them. Set \autoRecord: false` to keep them headless.`

login.spec.json
{
"tests": [
{
"steps": [
{ "goTo": "http://localhost:8092" },
{ "goTo": "http://localhost:8092/enhanced-elements.html" }
]
}
]
}

Doc Detective saves each video in the run folder, on a stable path. The same context lands on the same relative path in every run:

<outputDir>/.doc-detective/runs/<runId>/specs/<specId>/tests/<testId>/contexts/<contextId>/recordings/<contextId>.mp4

The recording runs alongside any record and stopRecord steps you write. An untargeted stopRecord never stops it, so a stray stopRecord: true can’t cut the video short. While recordings are on, the runFolder reporter runs even if reporters leaves it out. See Reporters and artifacts.

Where the recording shows up

The automatic recording isn’t a step, so it isn’t in a context’s steps, and summary.steps doesn’t count it. Each context in the results has its own autoRecording field:

testResults.json (one context)
{
"autoRecording": {
"result": "PASS",
"recordingPath": "specs/install-guide/tests/install/contexts/linux-chrome/recordings/linux-chrome.mp4",
"startedAt": "2026-11-06T02:33:29.010Z",
"format": "mp4",
"duration": 8.1,
"width": 1280,
"height": 720,
"fps": 30
}
}
FieldWhat it holds
resultPASS, FAIL, WARNING, or SKIPPED, from starting the recording through saving it.
resultDescriptionWhy, when the result isn’t PASS.
resultCodeWhat kind of failure it was, when the result is FAIL: environment or assertion.
recordingPathThe video’s path relative to the results’ runDir, with forward slashes. It’s there only when a file was saved.
startedAtWhen the recording started. It’s left out when the recording didn’t start.
format, duration, width, height, fpsThe saved video’s file format, length in seconds, size in pixels, and frame rate. Each is left out when Doc Detective couldn’t read it.

A FAIL or WARNING sets the context’s result, the way a step’s does. PASS and SKIPPED don’t, so a context whose steps were all SKIPPED stays SKIPPED.

The field is absent when Doc Detective didn’t try to record the context. That means one of these is true:

  • autoRecord is false.
  • The context drives no browser, app, or device.
  • A headless Chrome context has its own record step.
  • autoRecord is unset and the host check below failed.

Each reporter points at the video its own way:

ReporterWhere the recording shows up
html, and the run folder’s testResults.htmlThe video plays at the top of the context, in a panel named Automatic recording. When the result isn’t PASS, the panel also shows the result and the reason.
terminalA Recording: line with the absolute path, on each item the context lists.
markdown, and the run folder’s testResults.mdA Recording: path, relative to the summary file, on each item the context lists.
junitA [[ATTACHMENT…]] line holding the path, relative to junit.xml, on every test case that isn’t skipped.
json, and the run folder’s testResults.jsonThe context’s autoRecording field, with recordingPath relative to runDir.

The terminal, markdown, and junit reporters list a recording that didn’t pass as an item of its own, named <specId> › <testId> › <contextId> › autoRecording, with its reason. See What every reporter lists.

To watch a recording, open testResults.html in the run folder. The run prints its path after Run report:. The report loads the video from the run folder, so in CI, upload the whole folder. See Find the HTML report and Collect the run folder and artifacts.

Before you record

Once per run, before any test, Doc Detective checks what its recordings need on this host:

HostWhat it checks
Every hostDoc Detective’s own FFmpeg runs. It records the screen, converts the browser engine’s video, and encodes iOS device videos.
WindowsFFmpeg can capture one frame of the desktop, which needs a signed-in desktop session, not a service.
macOSThe app that runs Doc Detective, such as your terminal, IDE, or CI runner, has Screen Recording permission, and FFmpeg can see a screen.
LinuxDISPLAY works, or Xvfb is installed.

When a check fails, your tests still run:

  • Left unset, autoRecord records nothing the check covers. The run prints one warning with the fix:

    Warning: Not recording automatically: there's no display to capture. To record, install Xvfb or set DISPLAY, or set `autoRecord: false` to stop checking.
  • Set to true, the automatic recording is SKIPPED with the reason and the fix. So is any record step the check covers.

If the checks pass but an automatic recording still can’t start, it’s SKIPPED too. With autoRecord set to true, it fails instead: the context fails, and its steps are SKIPPED.

To give a macOS app Screen Recording permission, turn it on in System Settings > Privacy & Security > Screen Recording.

Turn it off

Set autoRecord to false at the config, spec, or test level. A test’s setting overrides a spec’s, which overrides the config’s:

.doc-detective.json
{
"autoRecord": false
}

For a single run, use the flag:

doc-detective --no-auto-record

The flag sets the config level, so a spec or test that sets autoRecord to true still records. true is strict: a recording the host can’t make is SKIPPED with the reason, rather than left out.

Verify it works

  • Each recorded context has an autoRecording field in the results, and its recordingPath names a video in the run folder.
  • A host that can’t record prints one Not recording automatically warning, and the tests still run.

Troubleshooting

A Firefox window opens during the run

Cause: the context is headless Firefox, and Doc Detective runs it headed so it can record it.

Solution: set autoRecord to false to keep it headless, or name chrome in the context, which records headless.

Recordings overlap on Windows or macOS

Cause: the run sets concurrentRunners above 1 and autoRecord to true, so the ffmpeg engine records the same physical screen for several contexts at once. Doc Detective warns when this happens.

Solution: leave autoRecord unset, which records those contexts one at a time, or use headless Chrome, which records each tab on its own. See Two concurrent recordings overlap on Windows or macOS.

What’s next