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:
- Doc Detective installed.
- A test with steps that drive a browser, a native app, or a device.
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:
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.`
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:
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:
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:
autoRecordisfalse.- The context drives no browser, app, or device.
- A headless Chrome context has its own
recordstep. autoRecordis unset and the host check below failed.
Each reporter points at the video its own way:
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:
When a check fails, your tests still run:
-
Left unset,
autoRecordrecords nothing the check covers. The run prints one warning with the fix: -
Set to
true, the automatic recording is SKIPPED with the reason and the fix. So is anyrecordstep 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:
For a single run, use the flag:
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
autoRecordingfield in the results, and itsrecordingPathnames a video in the run folder. - A host that can’t record prints one
Not recording automaticallywarning, 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
- Record video to record a flow, stop it, and choose an engine.
- Capture screenshots automatically, which is also on by default.
- Detect visual regressions with checkpoints to watch a recording for visual drift.
- Look up automatic-recording fields in Automatic recordings and the
configschema.