Testing Terraform scripts locally
Having the possibility to run Playwright Test scripts for your browser checks locally will allow you to develop them faster and with more confidence.
Enabling local script execution
You can easily enable local execution by storing your browser check scripts in local folders and passing the path to the right script:
Basic checks written with @playwright/test
will run locally with npx playwright test
and remotely on Checkly without any modifications:
If your script is using Page Object Models or imports other files, you can take advantage of Checkly’s code snippets. Consider the following directory structure:
scripts/snippets/shoppingCart.{js,ts}
contains a Page Object Model class encapsulating the logic for the store’s shopping cart page:
scripts/checkout.spec.{js,ts}
file is your Checkly check with the following content:
As you can see, it imports the ShoppingCart
class from the ./snippets/shoppingCart
directory and uses its methods and locators within the test. This setup will work out of the box locally with npx playwright test
. If you’d like to use the external files in Checkly, you’ll need to declare them as a checkly_snippet
resource in your .tf
file:
What’s worth noting
- Checkly will infer the name for the snippet file based on the
name
property of the resource schema. Hence, it’s best to name it the same as the local file. - The
./snippets/
path is where Checkly will make your snippets available. Use this directory in your Terraform setup to keep things consistent.
If you’d like to store the snippet files in a different directory, using environment variables to define the paths for local and remote execution could be a solution.
Last updated on December 13, 2024. You can contribute to this documentation by editing this page on Github