checkFile
The checkFile action waits for a finished file and, optionally, checks its text. Use it when a procedure ends with a file: an export a user downloads, or a report a command writes.
A file counts as finished once two things are true. It’s no longer an in-progress download, such as a .crdownload or .part file. Its size also stays the same for 250 ms.
Check a download
In Chrome and Firefox, Doc Detective saves every download to the context’s own download folder, with no prompt. To check a download, set download to a glob for its file name, after the step that starts it:
Each checkFile with download returns the oldest finished download that no earlier checkFile in the same context returned. Two exports followed by two checks return two different files. A download that finished before the step runs still counts.
The download folder is in the run folder, next to the context’s screenshots: .doc-detective/runs/<runId>/specs/<specId>/tests/<testId>/contexts/<contextId>/downloads/. Downloads never land in your own Downloads folder.
On Windows, Chrome can’t save a file whose full path is longer than 260 characters, and the step then times out. If a download never arrives, set
outputDirto a shorter folder, or shorten the spec and test IDs.
download needs a desktop Chrome or Firefox context, and a browser that an earlier step opened, such as goTo. Elsewhere, the step reports SKIPPED:
- In Safari:
Skipped: `safari` can't save downloads to a known folder. - On mobile, in an app, or with no browser open:
Skipped: `download` needs a desktop Chrome or Firefox context.
Check a file
To check any other file, set path to a glob, or set checkFile to the glob as a string. A relative path resolves against the spec file. When several files match, the newest finished one counts. path works in every context and needs no browser.
Fields
Set checkFile to a string, which is shorthand for path, or to an object with these fields:
path: a glob for the file to wait for. Setpathordownload.download: a glob for a file name in the context’s download folder. Setpathordownload.content: (Optional) Text the file must contain, read as UTF-8. A value that starts and ends with/is a regular expression, as inrunShell’sstdio.contentchecks raw text, so it suits text formats such as CSV, JSON, or logs, not PDF files. Adownloadcheck returns its file even whencontentdoesn’t match, so a later check moves on to the next download.timeout: (Optional) How long to wait for a finished match, in milliseconds. Defaults to30000.
Set path or download, not both. Setting both is a validation error.
Outputs. The step sets outputs.filePath (the absolute path), outputs.fileName, and outputs.fileSize (in bytes). To use them in later steps, set the step’s variables object, for example to $$filePath.
Failures. The step fails when no finished file matches within timeout, or when Doc Detective can’t read the file, or the file doesn’t contain content. For example:
Couldn't find a finished download matching `*.csv` within 30000 ms.Couldn't find a finished file matching `/abs/out/*.log` within 30000 ms.Couldn't find `Invoice` in `/abs/out/invoice.csv`.Couldn't read `/abs/out/invoice.csv`.
For every field, see the
checkFilereference.
Examples
Check the text of a download
This example waits up to a minute for an invoice export in CSV format and checks that it contains the word Invoice.
Check a command’s output file
This example checks that a build log reports a passing build.
Check more than the text
For checks beyond content, save the file’s path to an environment variable and read it in runShell or runCode. Read it through process.env, so Windows paths stay intact.