Detected tests
Doc Detective can automatically generate tests based on your documentation source files and your fileTypes configuration. Detected tests are useful for large, complex test suites that you want to keep in sync with your documentation. Step detection is on by default. With no extra configuration, the built-in file types detect steps from links, bold text, images, code blocks, and quoted text after Type, Enter, or Press. They skip code samples. To detect other content, define markup patterns and their actions in the fileTypes.markup array of your config, as described in Detect tests with selectors. To turn detection off, set detectSteps to false.
Detected tests are useful for keeping your tests in sync with your documentation. When you update your documentation, Doc Detective automatically updates the tests based on the new content. Detected tests are generated automatically. You can’t edit detected tests directly, but you can update your config or documentation source files to change the tests.
You can mix detected tests with inline tests to declare steps your content might not cover, such starting or stopping a recording.
Benefits of detected tests
Detected tests provide several advantages:
- Automatic synchronization: Tests update automatically when documentation changes
- Reduced maintenance: No need to manually update test specifications
- Consistent coverage: Ensures all documented procedures are tested
- Time savings: Eliminates the need to write many test specifications manually
Combine detected tests with inline tests for comprehensive test coverage with minimal manual effort.
Default markup patterns
Every built-in format (Markdown, HTML, AsciiDoc, and DITA) detects the same steps from links, bold text, images, code blocks, and quoted text after Type, Enter, or Press. What gets detected lists them. Doc Detective parses each file first, so text inside code blocks and inline code never becomes a step.
In Markdown, for example:
- goToUrl:
Go to [Page Name](https://example.com)generates agoTostep. - checkHyperlink: Every link to an
httporhttpsURL generates acheckLinkstep. - clickOnscreenText: Bold text after a click verb, such as
Click **Button Name**, generates aclickstep. - findOnscreenText: All bold text generates a
findstep. - screenshotImage: An image with the
.screenshotclass, such as{.screenshot}, generates ascreenshotstep. - typeText: A typing instruction in prose, such as
Type "Hello World", generates atypestep. - httpRequestFormat: A code block tagged
httpthat holds a request generates anhttpRequeststep. - runCode: A code block tagged
bash,python,py,javascript, orjsgenerates arunCodestep.
DITA also uses its semantic elements. <cmd>Click the <uicontrol>Submit</uicontrol> button</cmd> generates click and find steps, and <cmd>Type <userinput>text</userinput> into the <uicontrol>Field</uicontrol></cmd> generates a type step into that field.
For each format’s syntax, see Markdown, HTML, AsciiDoc, and DITA.
Example with detected tests
With the default configuration, Doc Detective takes the following Markdown and generates tests automatically:
Markdown:
Detected tests:
Custom markup patterns
You can extend or override the default patterns by defining custom markup patterns in your configuration:
A regex pattern matches the file’s raw text, code samples included. To match structure instead, such as bold text outside code, use a selector.
Default actions
If you only need to perform basic steps, you can define actions using a shorthand of only specifying the action name. Doc Detective uses default actions. It substitutes the first capture group from the regex pattern into the most common location for the action. When there are no capture groups, it substitutes the entire match.
The default actions are as follows:
checkLink
Check that the match returns a valid status code.
click
Click or tap the match.
goTo
Open the match as a URL in a browser.
find
Find an element on the current page that has an ARIA label that equals the match.
screenshot
Save a screenshot to a path equalling the match.
type
Type the match into the current page.
httpRequest
Make an GET request to the match.
runShell
Run the match as a shell command.
record
Start recording a video to a path equalling the match.
stopRecord
Stop recording a video.
wait
Wait for the specified duration.
loadVariables
Load environment variables from an .env file, where the path is the match.
saveCookie
Save a browser cookie, where the match is a cookie name or a .txt path. A name saves the cookie to the environment variable of the same name. A .txt path saves the cookie named for the file to that file in outputDir, which defaults to the directory you run Doc Detective from. For example, session.txt saves the session cookie.
loadCookie
Load a browser cookie, where the match is a cookie name or a .txt path. A name loads the cookie from the environment variable of the same name. A .txt path loads the cookie named for the file from that file in outputDir, which defaults to the directory you run Doc Detective from. For example, session.txt loads the session cookie.