Setting Up Your Environment
Installing Node.js and npm
Download and install Node.js from nodejs.org
Verify installation:bash
node --version npm --version
Setting up a new project
Create a new directory for your project:bash
mkdir playwright-project cd playwright-projectInitialize a new Node.js project:bash
npm init -y
Installing Playwright with TypeScript
Playwright provides an installer that sets up everything you need
npm init playwright@latestDuring the setup, select the following options:
Choose TypeScript when prompted
Select browsers you want to test on (Chromium, Firefox, WebKit)
Add GitHub Actions workflow if you plan to use CI
Configuring tsconfig.json
The Playwright installer creates a basic tsconfig.json file. Here's an explanation of key settings:
Understanding project structure
After installation, your project should have the following structure:
Key files:
playwright.config.ts: Configuration for your tests, including browsers, timeouts, and reporter settings.
tests/example.spec.ts: Example test file created by the installer.
package.json: Contains scripts to run your tests and project dependencies.
Running your first test
The installer creates an example test. Run it with:
To see a report of your test run:
To run tests with UI mode (for debugging):
Last updated