Playwright local testing environment¶
This project is used to help you quickly set up a Playwright testing environment on your machine. Follow the installation instructions to set things up initially, and then follow the section below the installation instructions to get started on writing and testing scripts.
Installation instructions¶
- Install NodeJS v18.17.0 or above
- Verify that NodeJS has been installed by running
node -v
- Download these two files: package.json and template.js and create a directory for them
- Navigate to where you moved these files in your terminal
- Run
npm i
to install the required dependencies - Run
npx playwright install
to install the browsers which Playwright will run - Run
node _template.js
to run the template script and confirm that everything is working fine. A screenshot of the page calledscreenshot.png
should be saved to this directory.
Writing and running scripts¶
- Make a copy of
_template.js
and rename the copy to whatever you like (for exampleloginPage.js
) - Write your script by modifying the contents of the
testPage
function - Test the script by running
node SCRIPT_FILE_NAME.js
(in this example it'd benode loginPage.js
) and watch how it works in the Chromium window that opens - Make changes as needed and test again
- When you feel that the script is working fine, copy over everything under the
UJS CODE
comment (thetestPage
function and any imports or helper functions you might have added) over to your Browser monitor in Sematext Cloud
Guides and tips¶
For some examples on how to write your scripts with Playwright, check out the following resources: - The official Playwright documentation - How to convert Puppeteer scripts into their Playwright equivalents - Examples of some common use cases - Examples seen in Sematext Cloud - Our 'Tips & Tricks' page