- a common login procedure
- a common navigation flow
- a common setup or teardown procedure
If you are using the Checkly CLI, you don’t need to use snippets. Use
import or require to add any local dependencies from your repo. Check the docs on using local dependencies to learn more.How to use snippets
To create a snippet, access the snippets section on the left side of the UI. When creating a snippet, note that the snippet name will be used as its filename. It’s not necessary to name the snippet with the.js file extension since this will be added automatically.
A snippet can be imported in Browser checks as well as setup and teardown scripts using the Node.js require function. When a check or script runs, snippets will be available in the ./snippets directory.
Find simplified file and directory structures for API and Browser checks below.
module.exports object.
Require a snippet named setup-library from within a Browser check, a setup or teardown script as follows:
- TypeScript
- JavaScript
./snippets in the path when requiring.
For example, to import a snippet named setup-library from another snippet:
- TypeScript
- JavaScript
script.js rather than be placed in the snippets directory. To import other snippets, the setup / teardown snippet should include the snippets directory in the path.
For example, import a snippet named setup-library using require('./snippets/helper.js').
Example: GitHub login
Say we want to validate some parts of the GitHub website only available to logged in users. We want to have separate, small Browser checks to have granular feedback whether each part functions. Create a snippet namedgithub_login in the “code snippets” section with a function that executes the login routine.
- TypeScript
- JavaScript
- We created a standard
asyncfunction that expects three parameters: thepageobject, ausernameand apasswordvariable. - We exported this function on the standard
module.exportsobject. - You now have a function you can call in any of your Browser checks to perform a login on GitHub.

- TypeScript
- JavaScript
GITHUB_USER and GITHUB_PWD environment variables and passing them to the gitHubLogin() function.
You should store these in your environment variables.