Skip to navigation

reStructuredText input format

reStructuredText (RST) is the markup language of Sphinx and docutils projects. Doc Detective reads inline tests from RST comments and detects steps from RST syntax, with no configuration. Doc Detective parses RST itself, so you don’t need Sphinx or docutils installed.

File extensions

Doc Detective processes reStructuredText files with the .rst extension.

To read files with another extension as RST, add a file type that extends rst to fileTypes in your config file:

{
"fileTypes": [
{
"name": "rst-notes",
"extends": "rst",
"extensions": ["txt"]
}
]
}

The extension picks the parser, so a .rst file always parses as RST, even in a file type that extends markdown.

A fileTypes list in your config replaces the default list. If your config already sets fileTypes, add "rst" to it to keep reading .rst files.

Inline test syntax

RST files use comments for inline tests. Put a blank line before and after each statement:

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

Test start:

.. test {"testId": "my-test"}

Step:

.. step {"goTo": "https://example.com"}

Test end:

.. test end

Ignore blocks:

.. test ignore start
Content to ignore
.. test ignore end

A comment holds its first line plus the indented block below it, so a long step can continue on the next lines:

.. step
{"find": "Welcome"}

Only comments hold statements. Directives (.. note::), hyperlink targets (.. _name:), footnotes (.. [1]), citations (.. [name]), and substitution definitions (.. |name|) aren’t comments.

Example

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

.. test {"testId": "doc-test"}
Getting started
===============
Navigate to the application:
.. step {"goTo": "https://app.example.com"}
Click the **Start** button:
.. step {"click": "Start"}
Enter your username:
.. step {"type": {"keys": "testuser", "selector": "[name=username]"}}
Submit the form:
.. step {"click": "Submit"}
.. test end

Detected tests

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

StepreStructuredText that matches
goToGo to `the site <https://example.com>`_, and the other navigation verbs
checkLinkAny embedded http or https link, such as `text <https://example.com>`_ or `text <https://example.com>`__, and any bare http or https URL
clickClick **Search**, and the other click verbs
findAny **bold** text
screenshotAn image or figure directive with :class: screenshot
typeType "kittens" in prose
httpRequestA code-block, code, or sourcecode directive tagged http, or a literal block, that holds a request such as GET https://example.com
runCodeA code-block, code, or sourcecode directive tagged bash, python, py, javascript, or js, unless it has :class: testIgnore. These steps are unsafe, so they run only with allowUnsafeSteps

A screenshot image’s source is the file to save:

.. image:: results.png
:alt: Search results
:class: screenshot

To show a command without running it, add :class: testIgnore:

.. code-block:: bash
:class: testIgnore
rm -rf build/

A literal block is the indented block after a paragraph that ends in ::. It has no language.

Comments, links, and formatting inside code blocks, literal blocks, inline literals (``text``), interpreted text and roles (:guilabel:`Save`), and raw directives aren’t read. In other directives, such as note and warning, the body is prose, but the text on the directive’s own line isn’t read.

Doc Detective reads links whose URL sits inside the link, as in `text <https://example.com>`_. To make a link detectable, write it that way rather than as a named reference to a .. _name: url target.

Because roles aren’t read, a UI label written as :guilabel:`Save` doesn’t become a step. To act on it, add a step, such as .. step {"click": "Save"}. To change what’s detected, see Selectors and custom inputs.

JSON and YAML syntax

RST inline tests support both JSON and YAML syntax:

JSON syntax:

.. test {"testId": "my-test"}
.. step {"goTo": "https://example.com"}

YAML syntax:

.. test testId: my-test
.. step goTo: https://example.com

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

Best practices

  • Put a blank line before and after each statement. A .. line that continues a paragraph is prose, not a comment.
  • Use descriptive test IDs to identify tests in results.
  • Write each link with its URL inside it, as in `text <https://example.com>`_, so Doc Detective detects it.
  • Combine inline tests with detected tests so links, bold text, and code blocks become steps without extra comments.

Includes

Doc Detective resolves .. include:: directives before it finds tests, so a test in an included file runs inside the page that includes it. It supports :start-line:, :end-line:, :start-after:, :end-before:, and / paths from the folder that holds conf.py. An included file doesn’t run on its own. See Test pages that include other files.

Effect on your build

RST test comments are standard RST comments, so Sphinx and docutils leave them out of the rendered output. Your build doesn’t change, and the tests stay in the source.

”Last verified on” dates

Doc Detective doesn’t write verification results into .rst files, and it skips them without a warning. In an RST file, a verified-by entry, a meta statement, and badge: true on a test statement have no effect, and verification.write leaves the file unchanged.

To record when an RST test last passed, give it a testId and name that ID in a verified-by entry on a page in another format. See Show a “Last verified on” date.

Next steps