A comprehensive demonstration of Playwright with JavaScript, showcasing both UI automation and API automation with best practices, testing frameworks, and production-ready patterns.
- β 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
.
βββ 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
- Node.js 18+ (Node.js 20+ recommended)
- npm or yarn
- Clone the repository
git clone <repository-url>
cd playwright-demo-js-full-stack- Install dependencies
npm install- Install Playwright browsers
npx playwright install- Configure environment variables
cp config/.env.example config/.env
# Edit config/.env with your settingsnpm testnpm run test:uinpm run test:apinpm run test:smokenpm run test:parallelnpm run test:debugnpm test
npm run test:reportnpx playwright test tests/ui/example.spec.js
npx playwright test tests/api/example.spec.jsnode main.jsTests demonstrate:
- Browser navigation
- Element interaction (click, type, select)
- Waiting for elements
- Taking screenshots
- Form submissions
- Assertion patterns
Tests demonstrate:
- GET requests
- POST requests with JSON payloads
- PUT/DELETE operations
- Response validation
- Status code assertions
- Error handling
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 testingjsonplaceholder.typicode.com: For API testing (fake JSON API)
See playwright.config.js for detailed configuration options.
| 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 |
- Playwright JavaScript Documentation
- Playwright Test Documentation
- Axios Documentation
- Page Object Model Pattern
- Never commit
.envfiles with sensitive data - Use
config/.env.exampleas a template - Store credentials in CI/CD secrets
This project is ready for GitHub Actions. See .github/workflows/ for automated test execution.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or suggestions, please open an issue on GitHub.
Happy Testing! π