A step-by-step tutorial for learning web automation with Playwright, designed specifically for non-technical people who want to learn testing.
- π Playwright - Modern browser automation framework
- π Data Tables - Pipe-delimited tables with dynamic values for comprehensive test scenarios
- π TypeScript - Type safety and better IDE support
- π Parallel Execution - Run tests in parallel for faster execution
- π HTML Reports - Comprehensive test reporting with built-in Playwright reporting
- π· Screenshots on Failure - Automatic screenshot capture for failed tests
- π― Cross-browser Testing - Support for Chrome, Firefox, and Safari
- π·οΈ Test Organization - Organized test structure with progressive learning approach
- πͺ Custom Fixtures - Advanced Playwright fixtures for enhanced testing capabilities
- π Tutorial Guide - Step-by-step learning path from beginner to advanced
- βοΈ Playwright Methods Reference - Complete API documentation with examples
- π Data Tables Guide - Pipe-delimited data tables with dynamic values in Playwright
- πͺ Playwright Hooks Guide - Advanced hooks and fixtures documentation
- π Official Playwright Docs - Comprehensive framework documentation
βββ tests/ # Playwright test files organized by learning progression
β βββ 00-quick-start.spec.ts # Basic Playwright introduction
β βββ 01-basic-navigation.spec.ts # Web navigation fundamentals
β βββ 02-finding-elements.spec.ts # Element location strategies
β βββ 03-clicking-interactions.spec.ts # User interactions and forms
β βββ 04-waiting-timing.spec.ts # Timing and waiting strategies
β βββ 05-advanced-scenarios.spec.ts # Real-world testing scenarios
β βββ 06-api-basics.spec.ts # API testing introduction
β βββ 07-api-methods.spec.ts # HTTP methods and CRUD operations
β βββ 08-api-advanced.spec.ts # Advanced API testing patterns
β βββ 09-advanced-hooks.spec.ts # Custom fixtures and hooks
β βββ 10-data-tables-consolidated.spec.ts # Data tables with dynamic values
βββ reports/ # Test reports and screenshots
β βββ cucumber-report.html # Legacy report (can be removed)
β βββ screenshots/ # Failure screenshots
βββ test-results/ # Playwright test results
βββ playwright-report/ # Built-in Playwright HTML reports
βββ allure-report/ # Allure reporting (optional)
βββ DATA-TABLES.md # Data tables documentation
βββ TUTORIAL.md # Complete tutorial guide
βββ PLAYWRIGHT-METHODS.md # API reference documentation
βββ PLAYWRIGHT-HOOKS-GUIDE.md # Hooks and fixtures guide
βββ test-base.ts # Custom Playwright fixtures
βββ global-setup.ts # Global test setup
βββ global-teardown.ts # Global test cleanup
βββ playwright.config.ts # Playwright configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Dependencies and scripts
-
Install dependencies:
npm install
-
Install Playwright browsers:
npx playwright install
-
Run all tests:
npx playwright test -
Run tests with UI mode (recommended for learning):
npx playwright test --ui -
Run tests in headed mode (see browser):
npx playwright test --headed
-
Run tutorial progression:
npx playwright test tests/00-quick-start.spec.ts # Start here npx playwright test tests/01-basic-navigation.spec.ts # Web basics npx playwright test tests/02-finding-elements.spec.ts # Element finding # ... continue through the numbered sequence
-
Run data tables examples:
npx playwright test tests/10-data-tables-consolidated.spec.ts -
Run API tests:
npx playwright test tests/0*-api-*.spec.ts
-
Generate and view HTML report:
npx playwright show-report
-
Run tests with tracing:
npx playwright test --trace on
Create a .env file based on .env.example:
cp .env.example .envAvailable environment variables:
BROWSER- Browser to use (chromium, firefox, webkit) - default: chromiumHEADLESS- Run in headless mode (true/false) - default: trueBASE_URL- Base URL for tests - default: https://www.google.comTIMEOUT- Test timeout in milliseconds - default: 30000
- Create test files in the
tests/directory using Playwright syntax - Use custom fixtures from
test-base.tsfor enhanced functionality - Follow the numbered progression for learning (00-quick-start.spec.ts through 10-data-tables.spec.ts)
Example test file:
import { test, expect } from '../test-base';
test.describe('Login functionality', () => {
test('should login successfully', async ({ managedPage }) => {
await managedPage.goto('/login');
await managedPage.fill('#username', 'testuser');
await managedPage.fill('#password', 'password123');
await managedPage.click('#login-button');
await expect(managedPage.locator('.welcome')).toBeVisible();
});
});Example with data tables:
// Pipe-delimited data table with dynamic values
const testDataWithHeaders = `
| username | password | expected |
| ${randomEmail()} | pass123 | success |
| invalid@test | ${empty()} | error |
| ${randomEmail()} | wrongpass | error |
`.trim();- Browser settings and test execution options
- Custom fixtures and global setup/teardown
- Report generation and screenshot settings
- Parallel execution and timeout configurations
- Compilation options optimized for Playwright
- Include/exclude patterns for test files
- Type definitions for enhanced IDE support
This project includes comprehensive documentation to help you learn and reference Playwright testing:
-
TUTORIAL.md - Complete step-by-step tutorial guide
- Progressive lessons from basic navigation to advanced API testing
- Learning objectives and practical examples for each lesson
- Beginner-friendly explanations of testing concepts
- Real-world scenarios and best practices
-
PLAYWRIGHT-METHODS.md - Comprehensive API reference
- Detailed documentation of 50+ Playwright methods
- Complete parameter explanations and available options
- Practical code examples and usage patterns
- Cross-references to tutorial lessons for integrated learning
- Official Playwright Documentation - Complete API reference and guides
- Playwright GitHub Repository - Source code and issue tracking
- Playwright Community - Community resources and support
Playwright generates comprehensive reports automatically:
- Built-in HTML report:
playwright-report/index.html - Test results:
test-results/directory with detailed logs - Screenshots: Automatically captured on test failures
- Legacy reports:
reports/directory (can be cleaned up)
- Chromium (Chrome/Edge)
- Firefox
- WebKit (Safari)
Set the browser using the BROWSER environment variable or in your .env file.
Organize and filter your tests using Playwright's built-in capabilities:
npx playwright test tests/0*-api-*.spec.ts # API tests only
npx playwright test tests/0[1-5]-*.spec.ts # Web UI tests (lessons 1-5)npx playwright test --grep "navigation" # Tests with "navigation" in the name
npx playwright test --grep "login|auth" # Tests related to login or authnpx playwright test --project=chromium # Chrome browser only
npx playwright test --project=firefox # Firefox browser only- Custom Fixtures - Use the custom fixtures from
test-base.tsfor enhanced functionality - Descriptive Test Names - Write clear and descriptive test descriptions
- Independent Tests - Ensure tests can run independently without dependencies
- Progressive Learning - Follow the numbered sequence for optimal learning
- Data Tables - Use the data table functionality for comprehensive test scenarios
- Error Handling - Leverage automatic screenshot capture and detailed reporting
This project includes comprehensive Allure reporting for beautiful, interactive test reports.
# Run tests and generate report
npm run test:with-report
npm run api:with-report
# Generate report from existing results
npm run report:generate
# Open report in browser
npm run report:open
# Serve report with auto-refresh
npm run report:serve- Test Results Overview - Summary of passed, failed, and skipped tests
- Test Execution Details - Step-by-step breakdown of each scenario
- Screenshots - Automatic screenshots on test failures
- API Request/Response Data - Full API interaction logs
- Historical Trends - Track test results over time
- Categories & Tags - Organized by lesson, difficulty, and test type
- allure-results/ - Raw test execution data
- allure-report/ - Generated HTML report
- Screenshots saved in reports/screenshots/
- Browser not found: Run
npx playwright install - Port conflicts: Check if any services are running on test ports
- Timeout errors: Increase timeout values in environment variables
Run tests with debugging enabled:
npx playwright test --headed --debugThis will:
- Run in headed mode with browser visible
- Pause execution for step-by-step debugging
- Show browser interactions in real-time
- Allow interactive debugging with the Playwright Inspector
- Playwright Official Website - Main Playwright site with getting started guides
- Playwright API Reference - Complete API documentation
- Playwright Test Runner - Built-in test runner documentation
- Cucumber.js Official Docs - BDD framework documentation
- Playwright GitHub - Source code and issue tracking
- Playwright Discord - Community chat and support
- Stack Overflow - Q&A with playwright tag
- Playwright University - Official learning path
- Test Automation University - Free courses
Happy Testing! ππ