Skip to content

sageIvan/playwright-cucumber

Repository files navigation

🎭 Playwright Tutorial Project

A step-by-step tutorial for learning web automation with Playwright, designed specifically for non-technical people who want to learn testing.

Features

  • 🎭 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

πŸ“– Quick Documentation Links

Project Structure

β”œβ”€β”€ 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

Getting Started

Installation

  1. Install dependencies:

    npm install
  2. Install Playwright browsers:

    npx playwright install

Running Tests

All Playwright Tests

  • 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

Specific Test Files

  • 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

Test Reports

  • Generate and view HTML report:

    npx playwright show-report
  • Run tests with tracing:

    npx playwright test --trace on

Environment Variables

Create a .env file based on .env.example:

cp .env.example .env

Available environment variables:

  • BROWSER - Browser to use (chromium, firefox, webkit) - default: chromium
  • HEADLESS - Run in headless mode (true/false) - default: true
  • BASE_URL - Base URL for tests - default: https://www.google.com
  • TIMEOUT - Test timeout in milliseconds - default: 30000

Writing Tests

  1. Create test files in the tests/ directory using Playwright syntax
  2. Use custom fixtures from test-base.ts for enhanced functionality
  3. 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();

Configuration

Playwright Configuration (playwright.config.ts)

  • Browser settings and test execution options
  • Custom fixtures and global setup/teardown
  • Report generation and screenshot settings
  • Parallel execution and timeout configurations

TypeScript Configuration (tsconfig.json)

  • Compilation options optimized for Playwright
  • Include/exclude patterns for test files
  • Type definitions for enhanced IDE support

Documentation

This project includes comprehensive documentation to help you learn and reference Playwright testing:

πŸ“š Learning Resources

  • 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

🌐 External Resources

Reports

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)

Browser Support

  • Chromium (Chrome/Edge)
  • Firefox
  • WebKit (Safari)

Set the browser using the BROWSER environment variable or in your .env file.

Test Organization

Organize and filter your tests using Playwright's built-in capabilities:

By File Pattern:

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)

By Test Name:

npx playwright test --grep "navigation"        # Tests with "navigation" in the name
npx playwright test --grep "login|auth"       # Tests related to login or auth

By Project (if configured):

npx playwright test --project=chromium         # Chrome browser only
npx playwright test --project=firefox         # Firefox browser only

Best Practices

  1. Custom Fixtures - Use the custom fixtures from test-base.ts for enhanced functionality
  2. Descriptive Test Names - Write clear and descriptive test descriptions
  3. Independent Tests - Ensure tests can run independently without dependencies
  4. Progressive Learning - Follow the numbered sequence for optimal learning
  5. Data Tables - Use the data table functionality for comprehensive test scenarios
  6. Error Handling - Leverage automatic screenshot capture and detailed reporting

Allure Reporting

This project includes comprehensive Allure reporting for beautiful, interactive test reports.

Generating 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

Report Features

  • 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

Report Structure

  • allure-results/ - Raw test execution data
  • allure-report/ - Generated HTML report
  • Screenshots saved in reports/screenshots/

Troubleshooting

Common Issues

  1. Browser not found: Run npx playwright install
  2. Port conflicts: Check if any services are running on test ports
  3. Timeout errors: Increase timeout values in environment variables

Debug Mode

Run tests with debugging enabled:

npx playwright test --headed --debug

This 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

πŸ”— Additional Resources

Official Documentation

Community Resources

Learning Materials


Happy Testing! πŸŽ­πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors