A minimal Playwright Test example repository showing a simple test structure, Playwright config, and npm scripts to run tests and view reports. This repo is intended as a learning starting point or quick template for writing end-to-end tests with @playwright/test.
- About
- Prerequisites
- Install
- Run tests
- Playwright configuration highlights
- Tests and examples
- Project structure
- Troubleshooting & tips
This repository demonstrates how to set up Playwright Test with a small number of example tests. It includes:
- A
playwright.config.tswith multi-browser projects (Chromium, Firefox, WebKit). - Example tests in the
tests/directory. - Useful npm scripts for running tests and viewing the built-in HTML report.
- Node.js 18 or newer (recommended). Check with
node -v. - npm (comes with Node.js) or a compatible package manager.
-
Clone the repository (if you haven't already):
git clone https://github.com/qa-shrine/Playwright-Basic-Example.git
-
Install dependencies:
npm installNote: Playwright browsers are downloaded automatically when you install @playwright/test. If you prefer to manage browser downloads manually, see Playwright docs.
Available npm scripts (defined in package.json):
npm test— run Playwright tests (headless by default).npm run test:headed— run tests in headed mode (browser windows visible).npm run test:report— open the Playwright HTML report from the last run.
Examples:
Run the full test suite (headless):
npm testRun tests with visible browsers (handy for debugging):
npm run test:headedAfter a run you can view the HTML report:
npm run test:reportKey settings are in playwright.config.ts:
testDir: './tests'— where tests live.timeoutandexpect.timeout— global test and assertion timeouts.fullyParallel: true— runs tests in parallel across workers.retries— set to2when running in CI (controlled byprocess.env.CI).reporter— consolelist+ anhtmlreport written toplaywright-report.use.baseURL— configured ashttps://practicetestautomation.com/.
The config also defines two projects to run the suite in Chromium and Firefox .
There are two example tests in tests/:
basic.spec.ts— simple smoke test that navigates tohttps://practicetestautomation.com/and asserts the page title contains "Practice Test Automation | Learn Selenium WebDriver".login.spec.ts— a small illustrative login flow that fills username/password inputs and verifies a welcome element. It uses role based selectors as a recommended practice for test stability.
These tests are intentionally minimal. Use them as templates when adding real tests for your application.
At a glance:
package.json # npm scripts and dev dependencies
playwright.config.ts # Playwright Test configuration
tests/ # Example test files
basic.spec.ts
login.spec.ts
README.md # (this file)
-
Browser not launching / tests failing locally:
- Ensure Node.js and npm are up-to-date.
- Reinstall deps and browsers:
npm cithennpx playwright install. - Try headed mode to see what the browser is doing:
npm run test:headed.
-
Tests are flaky:
- Prefer stable selectors (e.g.,
data-testid) over brittle CSS/XPath. - Increase timeouts in
playwright.config.tsor use explicit waits when necessary. - Use
trace(configured ason-first-retry) and the HTML report to debug failures.
- Prefer stable selectors (e.g.,
-
Running against a local app:
- If your app runs on a specific port, update
use.baseURLinplaywright.config.tsor callpage.goto()with the full URL.
- If your app runs on a specific port, update