docs/writing-visual-diff-tests.md
This document provides details for creating new visual diff tests. For other information about visual diff tests see testing.md.
First create a free BrowserStack account, use it to log into https://percy.io, create a project, and set the PERCY_TOKEN environment variable using the unique value you find at https://percy.io/<org>/<project>/integrations:
export PERCY_TOKEN="<unique-percy-token>"
Once the environment variable is set up, you can run the AMP visual diff tests. You can also pass this token directly to amp visual-diff --percy_token="<unique-percy-token>"
examples/visual-tests.test/visual-diff/visual-tests.jsonc JSON file. Documentation for the various settings are in that file.
url, nameloading_complete_css and maybe also loading_incomplete_cssviewport if your page looks different on mobile vs. desktop, and you intend to create a separate config for each
viewport setting wraps the entire DOM snapshot inside an <iframe> before uploading to Percy. Beware of weird iframe behaviors! 🐉enable_percy_javascript without consulting @ampproject/wg-infrainteractive_tests to a JavaScript file if you would like to add interactions to the page. See examples of existing interactive tests to learn how to write thoseNow, execute the test in development mode. Use --grep to filter down the list of available web pages. The value is a regular expression. e.g., amp visual-diff --grep="amp-[a-f]" will execute on tests that have an AMP component name between <amp-a...> through <amp-f...>.
amp visual-diff --dev --grep="<regular expression>"
Follow the development mode instructions and iterate on the test until you are satisfied.
Finally, verify that your test displays as expected by executing it on Percy:
amp visual-diff --grep="<regular expression>"
After approving your test, repeat the amp visual-diff command at least 5 more times. If any of the subsequent runs fails with a visual changes, this means that your test is flaky.
loading_complete_css configurations. You can repeat --dev mode until you find the right mix of complete and incomplete CSS selectors.--chrome_debug, --webserver_debug, or --debug for both.