This project demonstrates an end-to-end automation test suite for the TodoMVC application using Playwright with JavaScript.
The test suite covers adding, verifying, and deleting todos while ensuring the app is always restored to an ideal state after tests.
- Playwright (latest)
- JavaScript (Node.js)
- Page Object Model (POM) design
- Cross-browser support (Chromium, Firefox, WebKit)
- Artifacts for debugging (screenshots, video, traces)
├── pages/
│ └── TodoPage.js # POM class for TodoMVC page
├── tests/
│ └── todo.spec.js # Main test suite
├── playwright.config.js # Playwright configuration
└── README.md # Documentation
-
Clone the repository:
git clone https://github.com/hetsaliya-crestdata/todo-playwright-task.git cd todo-playwright-task -
Install dependencies:
npm install
-
Run tests:
npx playwright test -
Run tests for a specific browser:
npx playwright test --project=Firefox -
View the test report:
npx playwright show-report
- Encapsulates locators and methods in
pages/TodoPage.js. - Keeps test scripts clean and readable.
- Any UI change requires updating selectors only in the POM file.
-
Todo Input →
.new-todo- More stable than placeholder text (
"What needs to be done?"). - Prevents issues with i18n/localization or UI text changes.
- More stable than placeholder text (
-
Todo Items →
.todo-list li- Minimal and stable selector to fetch all todos.
-
Delete Button →
.destroy(revealed only on hover).
Configured in playwright.config.js:
- Retries failed tests up to 2 times.
- Runs across Chromium, Firefox, WebKit.
- Captures screenshots, video, and traces only on failure → efficient debugging without clutter.
-
After test:
- If test fails → clean up only the newly added todos (restore app to an ideal empty state).
This ensures:
- Tests remain independent.
- On Failures leave a clean state for the next test.
Steps:
- Add 3 new todos:
"Task One","Task Two","Task Three". - Verify that all 3 todos are added successfully.
- Delete the second newly added todo (
"Task Two"). - Verify only 2 todos remain:
"Task One"and"Task Three".
Expected Result: Todos are added, verified, and deleted correctly. The state is restored after test completion.
// playwright.config.js
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
testDir: './tests',
retries: 2, // retry failed tests
projects: [
{ name: 'Chromium', use: { browserName: 'chromium' } },
{ name: 'Firefox', use: { browserName: 'firefox' } },
{ name: 'WebKit', use: { browserName: 'webkit' } },
],
use: {
headless: true,
screenshot: 'only-on-failure',
video: 'retain-on-failure',
trace: 'on-first-retry',
},
reporter: [['html'], ['list']],
};
module.exports = config;- POM → Scalable, maintainable, and clean.
- Stable selectors → Avoids fragile placeholder text → i18n-safe.
- Retry logic → Handles flaky tests gracefully.
- Cross-browser → Ensures app works consistently across environments.
- Cleanup strategy → Keeps the instance consistent, avoids leftover data pollution.
- Artifacts → Videos, screenshots, and traces improve debugging.