8000 GitHub - gedom2012/playwright
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gedom2012/playwright

Repository files navigation

Playwright Test Automation

Playwright TypeScript GitHub Actions DotEnv Docker

Table of Contents

Project Overview

This project contains end-to-end (E2E) tests for the Sauce Labs checkout process using Playwright, a modern browser automation library. The tests are written in TypeScript and follow the Page Object Model (POM) design pattern for better maintainability.

Key Features:

  • Cross-browser testing (Chromium, Firefox, WebKit)
  • GitHub Actions integration
  • ESLint and Prettier for code quality
  • Husky Git hooks
  • Comprehensive test reporting

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18 or higher)
  • npm (v9 or higher) or yarn
  • Git

Installation

  1. Clone the repository:
    git clone https://github.com/gedom2012/playwright.git
    cd playwright
  2. Install dependencies:
    npm install
  3. Verify Playwright browsers are installed:
    npx playwright install

Environment Setup

The project requires environment variables for authentication. Follow these steps:

  1. Create your .env file:

    cp .env.example .env
  2. Edit the .env file with your credentials:

    USERNAME=your_actual_username
    PASSWORD=your_actual_password
  3. Important: Never commit your .env file to version control!

Docker Support

The project includes Docker configuration for containerized test execution:

Docker Files

  • Dockerfile: Based on official Playwright image with all dependencies

  • docker-compose.yaml: Defines the test service with volume mounts

Running Tests with Docker

  • Build the Docker Image
docker-compose build
  • Run Tests in Container
docker-compose up

Run Specific Test Command

  • Override the default command:
docker-compose run playwright-test npm run test-firefox

Persistent Reports

Reports are saved to your host machine through mounted volumes:

  • ./playwright-report/ - HTML test reports

  • ./test-results/ - Test artifacts and screenshots

Clean Up

  • Stop containers and remove volumes:
docker-compose down -v

Project Structure

.github/             # GitHub Actions workflows
.husky/              # Git hooks configuration
.vscode/             # VS Code settings
node_modules/        # Project dependencies
page-objects/        # Page object model classes
playwright-report/   # HTML test reports
test-results/        # Test artifacts and screenshots
tests/               # Test specifications
.env.example         # Environment variables template
.gitignore           # Git ignore rules
.eslint.config.mjs   # ESLint configuration
package.json         # Project metadata and scripts
package-lock.json    # Dependency lock file
playwright.config.ts # Playwright configuration
prettierrc           # Prettier configuration
Dockerfile           # Docker configuration
docker-compose.yaml  # Docker compose setup

Test Architecture

Dive deeper about of this test architecture with the following diagram

Running Tests

The project includes some test scripts configured in package.json:

Basic Commands

  • Run tests in Chromium:
npm run test-chrome
  • Run tests in Firefox:
npm run test-firefox
  • Run tests in WebKit:
npm run test-webkit
  • Run tests in all browsers in parallel:
npm run test-all

Advanced Options

  • Run specific test file:
npx playwright test tests/checkout.spec.ts
  • Run in headed mode (visible browser):
npx playwright test --headed
  • Generate trace for debugging:
npx playwright test --trace on

Test Reports

After test execution, you can view detailed reports:

  1. HTML Report:
npx playwright show-report

This opens an interactive HTML report showing test results, timelines, and screenshots.

  1. CI Report:

The GitHub Actions workflow includes a formatted test report in the workflow summary.

Linting and Formatting

The project uses ESLint and Prettier for code quality:

  1. Run linter:
npm run lint
  1. Format code:

Code is automatically formatted after save

Git Hooks

Pre-commit hooks automatically:

  • Format code with Prettier
  • Prevent commits with linting errors

Best Practices

This project follows these quality engineering best practices:

  • Page Object Model for maintainable selectors

  • Environment variables for sensitive data

  • Cross-browser testing coverage

  • Automated code quality checks

  • CI/CD integration with GitHub Actions

  • Containerized testing with Docker

Contributing

  1. Create a new branch for your feature/bugfix
  2. Write tests for new functionality
  3. Ensure all tests pass (npm run test-all)
  4. Run linter (npm run lint)
  5. Commit using conventional commit messages
  6. Open a pull request

💡 "Good code is its own best documentation." – Steve McConnell

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0