playwright-test-generator
v1.0.3
Published
Automated Page Object and Functional Test Generator for Playwright
Downloads
47
Maintainers
Readme
Playwright Test Generator 🎭
Automated Page Object and Functional Test Generator for Playwright with TypeScript support.
Features ✨
- 🎯 Automatic Page Object generation - Intelligently scans pages and creates type-safe Page Objects
- 🧪 Comprehensive functional test scenarios - Generates positive/negative test cases
- 🧭 Smart navigation discovery - Automatically detects navigation paths
- 📝 Form validation testing - Creates tests for form interactions and validations
- 🌍 Multi-environment support - Dev, QA, Prod environment configurations
- 💼 TypeScript support - Fully typed with excellent IDE support
- 🎨 Interactive CLI - User-friendly command-line interface
- ⚡ Fast setup - Get started in minutes
Installation 📦
npm install -g playwright-test-generatorQuick Start 🚀
1. Create environment files in your project:
# .env.qa
QA_APP_URL=https://your-qa-app.com
QA_USERNAME=testuser
QA_PASSWORD=testpass
# .env.dev
DEV_APP_URL=https://your-dev-app.com
DEV_USERNAME=devuser
DEV_PASSWORD=devpass2. Generate Page Objects:
generate-page-object --env qa3. Generate Functional Tests:
generate-functional-tests --env qa --depth 2CLI Commands 🛠️
Generate Page Object
generate-page-object [options]
Options:
-e, --env <environment> Environment (dev, qa, prod) (default: "qa")
-h, --headless Run in headless mode (default: false)
-o, --output <path> Output directory (default: "./pageObjects")
--help Display helpGenerate Functional Tests
generate-functional-tests [options]
Options:
-e, --env <environment> Environment (dev, qa, prod) (default: "qa")
-h, --headless Run in headless mode (default: false)
-d, --depth <number> Test depth (1 or 2) (default: "1")
-o, --output <path> Output directory (default: "./tests")
--help Display helpProgrammatic Usage 💻
import {
PageObjectGenerator,
TestScenarioGenerator,
NavigationHelper
} from 'playwright-test-generator';
// Use in your own scripts
const generator = new PageObjectGenerator(page);
await generator.generatePageObject('LoginPage', './pageObjects');Generated Output 📁
your-project/
├── pageObjects/
│ ├── LoginPage.ts
│ ├── DashboardPage.ts
│ └── UserManagementPage.ts
└── tests/
└── e2e/
├── loginTests.spec.ts
├── dashboardTests.spec.ts
└── userManagementTests.spec.tsExample Generated Page Object
import { Page, Locator, expect } from '@playwright/test';
export class LoginPage {
private page: Page;
constructor(page: Page) {
this.page = page;
}
// Locators
get usernameInput(): Locator {
return this.page.locator('input[name="username"]');
}
get passwordInput(): Locator {
return this.page.locator('input[name="password"]');
}
get loginButton(): Locator {
return this.page.locator('button[type="submit"]');
}
// Methods
async fillUsername(value: string): Promise<void> {
await this.usernameInput.fill(value);
}
async fillPassword(value: string): Promise<void> {
await this.passwordInput.fill(value);
}
async clickLogin(): Promise<void> {
await this.loginButton.click();
}
async verifyPageLoaded(): Promise<void> {
await this.page.waitForLoadState('networkidle');
}
}Requirements 📋
- Node.js 16+
- @playwright/test ^1.40.0
License 📄
MIT
Contributing 🤝
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Support 💬
- 📧 Email: [email protected]
- 🐛 Issues: GitHub Issues
- 📖 Docs: Documentation
