Skip to content

captain-nimo/playwright-demo-js-full-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Playwright JavaScript Full Stack Demo

A comprehensive demonstration of Playwright with JavaScript, showcasing both UI automation and API automation with best practices, testing frameworks, and production-ready patterns.

🎯 Features

  • βœ… UI Automation: Browser automation with Playwright (Chrome, Firefox, Safari, WebKit)
  • βœ… API Automation: REST API testing with axios
  • βœ… Page Object Model (POM): Scalable and maintainable test structure
  • βœ… Playwright Test: Modern testing framework with built-in features
  • βœ… Test Parallelization: Run tests in parallel with configurable workers
  • βœ… HTML Reports: Generate beautiful test reports
  • βœ… CI/CD Ready: GitHub Actions workflow included
  • βœ… Best Practices: Environment configuration, logging, and error handling

πŸ“‹ Project Structure

.
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ ui/                          # UI automation tests
β”‚   β”‚   β”œβ”€β”€ example.spec.js          # Example UI tests
β”‚   β”‚   └── pages/                   # Page Object Models
β”‚   β”‚       β”œβ”€β”€ BasePage.js          # Base page with common methods
β”‚   β”‚       └── HtmlPage.js          # HTML page object model
β”‚   β”œβ”€β”€ api/                         # API automation tests
β”‚   β”‚   β”œβ”€β”€ example.spec.js          # Example API tests
β”‚   β”‚   └── clients/                 # API client classes
β”‚   β”‚       └── ApiClient.js         # Base API client
β”‚   └── fixtures/
β”‚       └── fixtures.js              # Test fixtures and setup
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ logger.js                    # Logging utility
β”‚   └── helpers.js                   # Common helper functions
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ settings.js                  # Configuration management
β”‚   └── .env.example                 # Environment variables template
β”œβ”€β”€ scripts/
β”‚   └── check-env.js                 # Environment check script
β”œβ”€β”€ playwright.config.js             # Playwright configuration
β”œβ”€β”€ main.js                          # Quick start example
β”œβ”€β”€ package.json                     # Project dependencies
β”œβ”€β”€ .gitignore                       # Git ignore file
└── README.md                        # This file

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ (Node.js 20+ recommended)
  • npm or yarn

Installation

  1. Clone the repository
git clone <repository-url>
cd playwright-demo-js-full-stack
  1. Install dependencies
npm install
  1. Install Playwright browsers
npx playwright install
  1. Configure environment variables
cp config/.env.example config/.env
# Edit config/.env with your settings

πŸ“ Usage

Running All Tests

npm test

Running UI Tests Only

npm run test:ui

Running API Tests Only

npm run test:api

Running Smoke Tests

npm run test:smoke

Running Tests in Parallel

npm run test:parallel

Running Tests in Debug Mode

npm run test:debug

Generating and Viewing HTML Report

npm test
npm run test:report

Running Specific Test

npx playwright test tests/ui/example.spec.js
npx playwright test tests/api/example.spec.js

Quick Demo

node main.js

πŸ§ͺ Test Examples

UI Automation Example

Tests demonstrate:

  • Browser navigation
  • Element interaction (click, type, select)
  • Waiting for elements
  • Taking screenshots
  • Form submissions
  • Assertion patterns

API Automation Example

Tests demonstrate:

  • GET requests
  • POST requests with JSON payloads
  • PUT/DELETE operations
  • Response validation
  • Status code assertions
  • Error handling

πŸ”§ Configuration

Environment Variables

Create a config/.env file based on the template:

BASE_UI_URL=https://httpbin.org/html
API_BASE_URL=https://jsonplaceholder.typicode.com
BROWSER=chromium
HEADLESS=true
TIMEOUT=30000
SCREENSHOT_ON_FAILURE=true
API_TIMEOUT=10000

Note: The default URLs point to public test APIs:

  • httpbin.org: For UI automation testing
  • jsonplaceholder.typicode.com: For API testing (fake JSON API)

Playwright Configuration

See playwright.config.js for detailed configuration options.

πŸ“¦ Dependencies

Package Version Purpose
@playwright/test 1.50.0+ Browser automation and testing framework
axios 1.7.7+ HTTP API testing
dotenv 16.4.5+ Environment configuration
eslint 9.15.0+ Code linting
prettier 3.3.3+ Code formatting

πŸŽ“ Learning Resources

πŸ”’ Security

  • Never commit .env files with sensitive data
  • Use config/.env.example as a template
  • Store credentials in CI/CD secrets

πŸ“Š CI/CD Integration

This project is ready for GitHub Actions. See .github/workflows/ for automated test execution.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“§ Support

For issues, questions, or suggestions, please open an issue on GitHub.


Happy Testing! 🎭

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors