Skip to navigation

HTML is the standard format for web pages. Doc Detective reads inline tests from HTML comments and detects steps from HTML tags.

File extensions

Doc Detective processes HTML files with the following extensions:

  • .html
  • .htm

Inline test syntax

HTML files use HTML comments for inline tests:

<!-- test { "testId": "my-test" } -->
<!-- step { "goTo": "https://example.com" } -->
<!-- test end -->

Test start:

<!-- test { "testId": "my-test-start" } -->

Step:

<!-- step { "goTo": "https://example.com" } -->

Test end:

<!-- test end -->

Ignore blocks:

<!-- test ignore start -->
Content to ignore
<!-- test ignore end -->

Example

Here’s a complete example of an HTML file with inline tests:

<!DOCTYPE html>
<html>
<head>
<title>Getting Started</title>
</head>
<body>
<!-- test { "testId": "navigation-test" } -->
<h1>Getting Started</h1>
<p>Navigate to our homepage:</p>
<!-- step { "goTo": "https://example.com" } -->
<p>Click the menu button:</p>
<!-- step { "click": "Menu" } -->
<p>Enter your search query:</p>
<!-- step { "type": { "keys": "test query", "selector": "[name=search]" } } -->
<p>Submit the search:</p>
<!-- step { "click": "Search" } -->
<!-- test end -->
<p>For more information, see our <a href="https://docs.example.com">documentation</a>.</p>
</body>
</html>

Detected tests

With step detection on, HTML files detect the steps listed in What gets detected, from HTML tags:

StepHTML that matches
goToGo to <a href="https://example.com">the site</a>, and the other navigation verbs
checkLinkAny <a href> to an http or https URL
clickClick <strong>Search</strong> or Click <b>Search</b>, and the other click verbs
findAny <strong> or <b> text
screenshot<img src="results.png" class="screenshot">
typeType "kittens" in prose
httpRequestA <pre> block tagged language-http, or with no language, that holds a request
runCodeA <pre> block whose <code> has the class language-bash, language-python, language-py, language-javascript, or language-js. These steps are unsafe

Statements, tags, and text inside <pre>, <code>, <script>, and <style> aren’t read. Prose is read as written in the source, so Type &quot;kittens&quot; doesn’t match the type pattern. Write the quotes as ".

For a generated site, point Doc Detective at your source files rather than the build output. Otherwise, every link and bold phrase on every page becomes a step. To change what’s detected, see Selectors and custom inputs.

JSON and YAML syntax

HTML inline tests support both JSON and YAML syntax:

JSON syntax:

<!-- test { "testId": "my-json-test", "description": "Test description" } -->
<!-- step { "goTo": "https://example.com" } -->

YAML syntax:

<!-- test testId: my-yaml-test description: Test description -->
<!-- step goTo: https://example.com -->

Both formats work identically. Choose the format that’s most readable for your team.

Best practices

  • Keep test comments on a single line
  • Place test comments near the content they validate
  • Use descriptive test IDs to identify tests in results
  • Combine inline tests with detected tests so links, bold text, and code blocks become steps without extra comments
  • Validate your HTML to ensure comments don’t break document structure

Integration with HTML toolchains

HTML test comments are standard HTML comments and don’t affect page rendering or functionality. This makes Doc Detective tests invisible to browsers and build tools while still being testable.

Common HTML documentation tools that work with Doc Detective:

  • Static HTML sites: Any manually created HTML documentation
  • Generated HTML: HTML output from documentation generators
  • HTML help systems: CHM files and other HTML-based help formats
  • Single-page applications: SPAs with HTML documentation sections

Working with templated HTML

If you use templating systems (like Handlebars, Jinja2, or EJS), you can include Doc Detective comments in your templates:

Handlebars example:

{{#if showTutorial}}
<!-- test { "testId": "tutorial-test" } -->
<h2>Tutorial</h2>
<p>Navigate to the dashboard:</p>
<!-- step { "goTo": "{{dashboardUrl}}" } -->
<!-- test end -->
{{/if}}

The test comments remain in the generated HTML and can be processed by Doc Detective.

Next steps