Skip to content

AnuAknow/playwright

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Based on the repository structure and files you've provided, here's a comprehensive README.md for your Playwright testing repository:

# Playwright Testing Suite

A comprehensive test automation project using [Playwright](https://playwright.dev/), a modern end-to-end testing framework that supports Chromium, Firefox, and WebKit browsers.

## πŸ“‹ Project Overview

This repository contains automated tests for web applications, including:
- **Basic Example Tests**: Simple test cases demonstrating Playwright fundamentals
- **Todo App Tests**: Comprehensive test suite for a demo TodoMVC application
- **Multi-browser Support**: Tests run across Chromium, Firefox, and WebKit

## πŸš€ Getting Started

### Prerequisites

- **Node.js**: v18 or higher
- **npm**: v8 or higher

### Installation

1. Clone the repository:
```bash
git clone https://github.com/AnuAknow/playwright.git
cd playwright
  1. Install dependencies:
npm install

This will install:

  • @playwright/test (v1.50.1) - Playwright testing framework
  • @types/node (v22.13.1) - TypeScript definitions for Node.js

πŸ“ Project Structure

playwright/
β”œβ”€β”€ practice/
β”‚   └── tests/
β”‚       └── example.spec.ts           # Basic Playwright examples
β”œβ”€β”€ tests-examples/
β”‚   └── demo-todo-app.spec.ts         # Comprehensive TodoMVC app tests
β”œβ”€β”€ playwright.config.ts              # Playwright configuration
β”œβ”€β”€ package.json                      # Project dependencies
β”œβ”€β”€ package-lock.json                 # Locked dependency versions
β”œβ”€β”€ .gitignore                        # Git ignore rules
└── playwright.code-workspace         # VS Code workspace settings

πŸ“ Test Files

practice/tests/example.spec.ts

Basic example tests demonstrating core Playwright functionality:

  • Page navigation and title verification
  • Link interaction and heading validation

tests-examples/demo-todo-app.spec.ts

Comprehensive test suite for a TodoMVC application with extensive coverage:

  • New Todo: Adding and managing todo items
  • Mark all as completed: Bulk operations on todos
  • Item Management: Individual item interaction and state management
  • Editing: Edit, save, trim, and delete functionality
  • Counter: Item count tracking
  • Clear Completed: Removing completed items
  • Persistence: LocalStorage data persistence across sessions
  • Routing: Navigation between views (All, Active, Completed)

Key testing patterns include:

  • Element locators (placeholder, role, testId)
  • State assertions and class verification
  • LocalStorage validation
  • User interaction simulation
  • Multi-step test scenarios with test.step()

βš™οΈ Configuration

playwright.config.ts

Configures test execution with:

  • Test Directory: ./practice/tests
  • Parallel Execution: Enabled for faster test runs
  • Reporters: HTML report generation
  • Browsers: Chromium, Firefox, and WebKit
  • Tracing: Enabled on first retry for debugging
  • CI/CD Support: Configurable for CI environments

πŸ§ͺ Running Tests

Run all tests

npx playwright test

Run tests in a specific file

npx playwright test practice/tests/example.spec.ts

Run tests in a specific browser

npx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkit

Run tests with UI mode (interactive)

npx playwright test --ui

Run tests in debug mode

npx playwright test --debug

View test reports

npx playwright show-report

πŸ” Test Patterns Used

Locators

  • Role-based: page.getByRole('button', { name: 'Clear completed' })
  • Placeholder: page.getByPlaceholder('What needs to be done?')
  • Test ID: page.getByTestId('todo-item')
  • Text: page.getByText('3 items left')

Assertions

  • Visibility: toBeVisible(), toBeHidden()
  • Content: toHaveText(), toContainText(), toHaveTitle()
  • State: toBeChecked(), toBeEmpty(), toHaveClass()
  • Count: toHaveCount()

User Interactions

  • Navigation: page.goto(), page.goBack()
  • Click: .click(), .check(), .uncheck()
  • Input: .fill(), .press()
  • Advanced: .dblclick(), .dispatchEvent()

πŸ› οΈ Helper Functions

The TodoMVC test suite includes utility functions:

// Create multiple todo items
async function createDefaultTodos(page: Page)

// Verify todo count in LocalStorage
async function checkNumberOfTodosInLocalStorage(page: Page, expected: number)

// Verify completed todo count in LocalStorage
async function checkNumberOfCompletedTodosInLocalStorage(page: Page, expected: number)

// Verify specific todo exists in LocalStorage
async function checkTodosInLocalStorage(page: Page, title: string)

πŸ“Š CI/CD Integration

The configuration supports CI/CD pipelines with:

  • forbidOnly: Prevents test.only from reaching CI
  • retries: 2 retries in CI, 0 in local development
  • workers: 1 worker in CI for stability, unlimited locally
  • trace: Automatic trace collection for failed tests

πŸ”— Resources

πŸ“¦ Dependencies

Package Version Purpose
@playwright/test ^1.50.1 Testing framework
@types/node ^22.13.1 TypeScript type definitions

🎯 Best Practices

  1. Use specific locators: Prefer role-based or test ID locators over brittle selectors
  2. Wait for elements: Use Playwright's built-in waiting instead of hardcoded delays
  3. Organize tests: Group related tests using test.describe()
  4. Setup/Teardown: Use beforeEach and afterEach hooks for test isolation
  5. Helper functions: Extract common operations into reusable functions
  6. Assertions first: Verify one thing per assertion for clear failure messages

πŸ“„ License

ISC

πŸ‘€ Author

AnuAknow


Last Updated: April 7, 2026


Now let me create this README in your repository:I've created a comprehensive README.md for your AnuAknow/playwright repository. Here's what I included:

**README Structure:**

1. **Project Overview** - Introduction to the Playwright test suite with links to official documentation

2. **Quick Start** - Installation and setup instructions including:
   - Prerequisites (Node.js 18+)
   - Dependency installation
   - Playwright browser installation

3. **Project Structure** - Breakdown of the repository organization:
   - Test directories and their purposes
   - Configuration files
   - Helper utilities

4. **Configuration** - Details about `playwright.config.ts`:
   - Test directory settings
   - Parallel execution
   - Retry logic for CI environments
   - Browser projects (Chromium, Firefox, WebKit)
   - HTML reporting

5. **Running Tests** - Commands for:
   - Running all tests
   - Running specific test files
   - Running tests in headed mode
   - Running tests in UI mode
   - Debugging with Inspector

6. **Test Files Overview**:
   - **example.spec.ts** - Basic Playwright patterns
   - **demo-todo-app.spec.ts** - Advanced patterns including test organization, hooks, state verification, and localStorage testing

7. **Helper Functions** - Documentation of utility functions from demo-todo-app.spec.ts:
   - `createDefaultTodos()` - Creates test data
   - `checkNumberOfTodosInLocalStorage()` - Validates localStorage state
   - `checkNumberOfCompletedTodosInLocalStorage()` - Checks completion status
   - `checkTodosInLocalStorage()` - Verifies specific items

8. **Best Practices** - Guidelines for writing maintainable tests

9. **Dependencies** - Listed dev dependencies with versions

The README provides a complete guide for developers to understand and work with your Playwright testing suite.

About

Intial Playwright Install

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors