This project is a migration from Selenium Java to Playwright TypeScript for PageFly Company's test automation framework.
- Playwright TypeScript: Modern, fast, and reliable browser automation
- Page Object Model: Clean, maintainable test structure
- Cross-browser Testing: Support for Chromium, WebKit, and Firefox
- Allure Reporting: Beautiful test reports with screenshots and videos
- Parallel Execution: Run tests in parallel for faster execution
- Data-driven Testing: Support for multiple test data scenarios
- Environment Configuration: Flexible configuration for different environments
Before you begin, make sure you have the following installed:
- Node.js (v18 or higher)
- npm or yarn
- Git
-
Clone the repository (if not already done):
git clone <repository-url> cd pfcompany_playwright
-
Install dependencies:
npm install
-
Install Playwright browsers:
npm run test:install
-
Set up environment variables:
cp config.env .env # Edit .env file with your configuration
Copy config.env to .env and update the following variables:
# Environment Configuration
ENVIRONMENT=RC
BASE_URL=https://rc.pagefly.io
# Store Configuration
STORE=your_shopify_store_name
PASSWORD=your_shopify_store_password
# Browser Configuration
BROWSER=chromium
HEADLESS=falseThe playwright.config.ts file contains:
- Test directory configuration
- Browser settings
- Reporter configuration
- Timeout settings
- Parallel execution settings
# Run all tests
npm test
# Run tests in headed mode (see browser)
npm run test:headed
# Run tests with UI mode
npm run test:ui
# Run tests in debug mode
npm run test:debug
# Generate test code
npm run test:codegen# Run specific test file
npx playwright test src/tests/main-test.ts
# Run tests matching a pattern
npx playwright test --grep "Page Listing"
# Run tests in specific browser
npx playwright test --project=chromium
# Run specific test suites
npm run test:v2 # Run V2 tests
npm run test:v1 # Run V1 legacy tests
npm run test:api # Run API tests
npm run test:suites # Run all test suites
npm run test:editor # Run editor tests
npm run test:ab-testing # Run AB testing tests
npm run test:legacy # Run legacy tests# Run in headless mode
HEADLESS=true npm test
# Run with different environment
ENVIRONMENT=LIVE npm test
# Run with custom timeout
npx playwright test --timeout=120000# Generate and open HTML report
npx playwright show-report# Generate Allure report
npm run test:reportpfcompany_playwright/
βββ src/
β βββ config/ # Configuration files
β β βββ framework-constants.ts
β β βββ url-constants.ts
β βββ data/ # Test data and data providers
β β βββ data-provider.ts
β βββ pages/ # Page Object Model
β β βββ base-page.ts
β β βββ bridge.ts
β β βββ page-editor.ts
β β βββ page-listing-page.ts
β β βββ editor/ # Editor-specific page objects
β β βββ editor-canvas.ts
β β βββ elements-drawer.ts
β β βββ page-inspector.ts
β β βββ templates-drawer.ts
β βββ tests/ # Test files
β β βββ base/
β β β βββ base-test.ts
β β βββ v2/ # V2 modern tests
β β β βββ editor/
β β β β βββ editor-test.ts
β β β β βββ drag-and-drop-test.ts
β β β β βββ inspector-test.ts
β β β βββ ab-testing/
β β β βββ ab-testing-test.ts
β β βββ v1/ # V1 legacy tests
β β β βββ legacy/
β β β βββ page-editing-test.ts
β β βββ api/ # API tests
β β β βββ page-api-test.ts
β β βββ suites/ # Test suites
β β β βββ v2-suite.ts
β β β βββ v1-suite.ts
β β β βββ api-suite.ts
β β β βββ all-suites.ts
β β βββ main-test.ts
β β βββ page-listing-test.ts
β βββ types/ # TypeScript type definitions
β β βββ enums.ts
β β βββ element-types.ts
β β βββ device-modes.ts
β β βββ inspector-types.ts
β β βββ rich-text-types.ts
β βββ utils/ # Utility functions
β βββ webui.ts
β βββ image-utils.ts
β βββ clipboard-helper.ts
β βββ allure-manager.ts
βββ playwright.config.ts # Playwright configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Dependencies and scripts
βββ README.md # This file
The webui.ts module provides common browser automation functions:
- Element interactions (click, fill, hover)
- Waits and assertions
- Screenshot capture
- JavaScript execution
- Local storage management
- base-page.ts: Common page utility functions
- bridge.ts: Main navigation functions
- page-listing-page.ts: Page listing functionality
- page-editor.ts: Enhanced page editor with canvas, elements drawer, and inspector
- Editor Components (
src/pages/editor/):- EditorCanvas: Canvas interaction functionality
- ElementsDrawer: Elements drawer functionality
- PageInspector: Inspector panel functionality
- TemplatesDrawer: Templates drawer functionality
- base-test.ts: Provides fixtures for page
- Browser context configuration
- Common test setup and teardown
- V2 Tests (
src/tests/v2/): Modern editor and AB testing tests - V1 Legacy Tests (
src/tests/v1/): Legacy page editing tests - API Tests (
src/tests/api/): API functionality tests - Test Suites (
src/tests/suites/): Organized test suites
- Image Utils: Image manipulation utilities
- Clipboard Helper: Clipboard operations
- Allure Manager: Allure reporting utilities
import { test, expect } from './base/base-test';
import { openWebsite, click } from '../utils/webui';
test.describe('Feature Tests', () => {
test('should perform some action', async ({ page }) => {
// Test implementation
await openWebsite(page, 'https://example.com');
await click(page, 'button');
await expect(page.locator('text=Success')).toBeVisible();
});
});import { openPageListingPage } from '../pages/bridge';
import { clickCreatePage } from '../pages/page-listing-page';
test('should create a new page', async ({ page }) => {
await openPageListingPage(page);
await clickCreatePage(page);
// ... rest of test
});npm run test:debug- Screenshots are automatically captured on test failures
- Videos are recorded for failed tests
- Traces are available for debugging
// In your test
console.log('Debug information');
await page.screenshot({ path: 'debug.png' });| Selenium Java | Playwright TypeScript |
|---|---|
WebDriver |
Page |
WebElement |
Locator |
WebDriverWait |
Built-in auto-waiting |
Actions |
page.mouse / page.keyboard |
@Test |
test() |
@BeforeMethod |
test.beforeEach() |
- Faster Execution: No WebDriver overhead
- Better Reliability: Built-in waiting mechanisms
- Modern API: Async/await support
- Cross-browser: Single API for all browsers
- Better Debugging: Built-in tracing and debugging tools
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
- Use Function-Based Approach: Keep tests clean and maintainable with pure functions
- Use Data Providers: For data-driven tests
- Add Proper Waits: Use Playwright's built-in waiting
- Write Descriptive Tests: Clear test names and descriptions
- Handle Flakiness: Use retries and proper waits
- Keep Tests Independent: Each test should be able to run alone
- Import Only What You Need: Use specific function imports for better tree-shaking
-
Browser Installation:
npx playwright install
-
Permission Issues (macOS):
# Allow ChromeDriver in System Preferences > Security & Privacy -
Timeout Issues:
- Increase timeout in
playwright.config.ts - Use proper waits in tests
- Increase timeout in
-
Element Not Found:
- Check if element is in iframe
- Use proper selectors
- Add explicit waits
- Check Playwright documentation: https://playwright.dev/
- Review test logs and screenshots
- Use debug mode for step-by-step execution
This project is licensed under the MIT License.
- Original Selenium Java framework team
- Playwright team for the excellent tooling
- PageFly team for the migration requirements