Selenium to Playwright Migration Part 2: Setup and Configuration
This is part of the Selenium to Playwright Migration Series. Follow the complete 7-part tutorial to migrate your test suite from Selenium Java to Playwright TypeScript.
๐ญ Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Convert your build tools, test configuration, environment handling, and CI pipelines from Selenium/Maven/TestNG to Playwright/npm/TypeScript. Playwright replaces ~10 separate Java dependencies with a single package.
Contents
Dependency Mapping: pom.xml to package.json
| Selenium Dependency | Playwright Equivalent | Notes |
|---|---|---|
| selenium-java | @playwright/test | Core framework |
| testng | Built-in test runner | No extra package needed |
| allure-testng | Built-in reporters | HTML, JSON, JUnit built-in |
| assertj-core | Built-in expect() | Web-first assertions with auto-retry |
| log4j-core | Built-in console / Trace Viewer | Trace viewer replaces most logging |
| poi + poi-ooxml | JSON files + TypeScript types | No Excel needed for test data |
| WebDriverManager | npx playwright install | Bundled browser management |
| REST Assured | Built-in APIRequestContext | API testing included |
Configuration: testng.xml to playwright.config.ts
Before (TestNG XML)
<suite name="VWO Suite" parallel="methods" thread-count="2">
<listeners>
<listener class-name="...RetryListener"/>
<listener class-name="...ScreenshotListener"/>
</listeners>
<test name="VWO Login Tests">
<classes>
<class name="...TestVWOLogin">
<methods>
<include name="testPositiveLogin"/>
<include name="testNegativeLogin"/>
</methods>
</class>
</classes>
</test>
</suite>
After (playwright.config.ts)
import { defineConfig, devices } from '@playwright/test';
import * as dotenv from 'dotenv';
dotenv.config();
export default defineConfig({
testDir: './src/tests',
fullyParallel: true,
workers: process.env.CI ? 2 : 3,
retries: process.env.CI ? 2 : 0,
timeout: 60_000,
expect: { timeout: 10_000 },
reporter: [
['html', { open: 'never' }],
['json', { outputFile: 'test-results/results.json' }],
['list'],
],
use: {
baseURL: process.env.BASE_URL,
trace: 'on-first-retry',
video: 'retain-on-failure',
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
],
});
What replaced what: parallel="methods" thread-count="2" became fullyParallel: true, workers: 3. Listeners (RetryListener, ScreenshotListener) became retries, screenshot, video, trace config options.
๐ Level Up Your Playwright
From locators to CI pipelines โ build a production-grade Playwright + TypeScript framework step by step.
Environment: data.properties to .env
Before (Java Properties)
// data.properties
vwoURL=https://app.vwo.com
username=user@test.com
password=Test@4321
// PropertiesReader.java
public class PropertiesReader {
static Properties prop = new Properties();
static {
FileInputStream fis = new FileInputStream("src/main/resources/data.properties");
prop.load(fis);
}
public static String readKey(String key) {
return prop.getProperty(key);
}
}
After (.env + TypeScript config)
// .env
BASE_URL=http://localhost:3000
API_BASE_URL=http://localhost:3000/api
TEST_USERNAME=testuser@example.com
TEST_PASSWORD=SecurePass123
// src/config/index.ts
import * as dotenv from 'dotenv';
dotenv.config();
export const AppConfig = {
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
apiBaseUrl: process.env.API_BASE_URL || '',
testUser: {
email: process.env.TEST_USERNAME || '',
password: process.env.TEST_PASSWORD || '',
},
timeouts: { api: 30_000, default: 30_000 },
} as const;
CI/CD: Maven to GitHub Actions
name: Playwright Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test --shard=${{ matrix.shard }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-${{ strategy.job-index }}
path: playwright-report/
retention-days: 30
4-shard parallelization: Playwright splits tests across 4 CI runners automatically. No Selenium Grid needed.
Next: Part 3: The Master Cheat Sheet โ every Selenium Java pattern mapped to Playwright TypeScript across 16 categories.
๐ Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
