QA PRACTICE•FRAMEWORK
Playwright TypeScript · Selenium Java
Framework
Compare Playwright (TypeScript) and Selenium (Java) on the same E2E flow, then see how a modern framework is built: layers, folder structure, key code, a checklist and common mistakes.
Same check · two tools
Choose your automation framework
Learn the same stable locator and assertion pattern in Playwright (TypeScript) and Selenium (Java).
123456789
import { test, expect } from '@playwright/test';
test('user can add a product to the cart', async ({ page }) => {
await page.goto('https://qapractice.hakdogan.com/ecommerce');
await page.getByTestId('product-search').fill('Keyboard');
await page.getByRole('button', { name: /add keyboard to cart/i }).click();
await expect(page.getByTestId('cart-count')).toHaveText('1');
});Live browser runner
Write and run a focused check
Playwright-style commands execute against the practice target below. Try changing the locator or expected text and read the failure log.
Practice target
Profile settings
Not run yet
Run the example to see command results.
Lesson 1 of 4 · Beginner
Automate the Inputs test
You already tested this form manually in Practice. Now learn how the same check is organised in Playwright (TypeScript) and Selenium (Java).
Goal
Connect an acceptance criterion to code.
Files
Spec + Page Object + fixture.
Time
About 15 minutes · no account.
Lesson path
Progress
1 of 7 steps
inputs.spec.ts
Test: what to verify
123456789101112131415
import { test, expect } from '@playwright/test';
import { InputsPage } from './inputs.page';
test('invalid email shows a field error', async ({ page }) => {
const inputs = new InputsPage(page);
await inputs.goto();
await inputs.fillEmail('not-an-email');
await inputs.fillPassword('Pass-w0rd!');
await inputs.submit();
// The error also contains an icon ("!"), so assert the message with toContainText.
await expect(inputs.emailError).toContainText(
'Please enter a valid email address.',
);
});Run it
$ npx playwright test inputs.spec.tsAcceptance criteria → assertions
- AC-002 Invalid email is rejected →
emailError.toContainText() - AC-003 Error appears beside the field →
getByTestId('email-error') - AC-006 Focus order is logical → add the keyboard step next
Common mistakes
- Do not put raw selectors in the spec.
- Do not use
waitForTimeoutfor validation. - Keep assertions in the test so the expected behaviour is visible.
Your turn
Write the positive Inputs test, then continue with Buttons.
Build it from scratch
A modern UI test framework, step by step
Small layers with one job each, so a test reads like the requirement and a UI change is fixed in one place. Pick a stack to see the structure, the key code and what to add as the suite grows.
12345678910111213141516171819
e2e/
├─ tests/
│ ├─ auth.setup.ts sign in once, save the session
│ ├─ login.spec.ts
│ └─ checkout.spec.ts
├─ pages/ Page Objects (one per screen)
│ ├─ login.page.ts
│ └─ profile.page.ts
├─ components/ shared widgets (toast, header)
├─ fixtures/index.ts test.extend(): page objects, api, data
├─ utils/ api.ts, format.ts, helpers
├─ data/ test data builders
├─ config/env.ts typed environment variables
├─ playwright.config.ts
├─ playwright-report/ generated HTML report (git-ignored)
├─ .env.example committed; real .env is ignored
├─ .gitignore · tsconfig.json · eslint.config.mjs
├─ package.json
└─ README.mdLayers · who owns what
- 1Test (spec). The scenario and the assertions. Reads like the acceptance criterion.
- 2Fixture. Setup and teardown. Gives each test its page objects and a clean state.
- 3Page Object. Locators and user actions. No assertions about business rules.
- 4Utils and data. Auth, API setup, builders, waits. Shared, small and tested by use.
- 5Config. URLs, credentials, timeouts, browsers. Never hard-coded in code above.
Each layer only calls the one below it. Tests never touch the driver or raw locators.
Folder structure
tests/— Specs: one user journey per file, tagged @smoke / @regression. auth.setup.ts signs in once.pages/— Page Objects: locators and user actions for one screen.components/— Reusable widgets used by many pages (header, toast, modal).fixtures/— test.extend(): injects page objects, API client and data into tests.utils/— Small helpers: API client, formatting, waits. No assertions about the product.data/— Test data builders and static data. Pure functions, no I/O.config/env.ts— One typed place that reads environment variables.playwright.config.ts— Projects, retries, reporters, trace and screenshots..env.example— Documents the variables a new teammate must set. Real .env is git-ignored.playwright-report/ · test-results/— Generated: the HTML report, traces, screenshots and videos. Git-ignored.
Key building blocks
One class per screen. It knows where things are and how a user acts on them.
1234567891011121314151617181920212223242526
import { type Locator, type Page } from '@playwright/test';
export class LoginPage {
readonly email: Locator;
readonly password: Locator;
readonly submit: Locator;
readonly formError: Locator;
constructor(private readonly page: Page) {
this.email = page.getByLabel('Email');
this.password = page.getByLabel('Password');
this.submit = page.getByRole('button', { name: 'Sign in' });
this.formError = page.getByRole('alert');
}
async goto() {
await this.page.goto('/login');
}
/** A user action, not a click. Tests read like the business flow. */
async signIn(email: string, password: string) {
await this.email.fill(email);
await this.password.fill(password);
await this.submit.click();
}
}12345678910
import { type Locator, type Page } from '@playwright/test';
/** A widget used on many screens lives in components/, not in every page object. */
export class Toast {
readonly root: Locator;
constructor(page: Page) {
this.root = page.getByRole('status');
}
}- ✓Locators are properties; actions are methods named after what the user does.
- ✓Prefer getByRole, getByLabel and getByTestId. Avoid long CSS and XPath chains.
- ✓Keep expect() in the spec so the expected behaviour is visible in the test.
Commands
- Run everything
npx playwright test - Smoke only
npx playwright test --grep @smoke - One file, headed
npx playwright test tests/login.spec.ts --headed - Open the last report
npx playwright show-report - Replay a failed test (trace)
npx playwright show-trace test-results/<test>/trace.zip - Debug with the inspector
npx playwright test --debug
Checklist
What a modern framework needs
Start with Core. Add the rest when the suite and the team grow — not before.
- CoreLayered structure
Tests stay short and a UI change is fixed in one place.
Playwright: spec → fixture → page object → utils
- CoreLocator policy
Stable locators are the biggest factor in flaky tests.
Playwright: getByRole, getByLabel, getByTestId first; CSS last
- CoreWaiting strategy
Fixed sleeps make tests slow and still flaky.
Playwright: Auto-wait and web-first expect(); no waitForTimeout
- CoreConfig and environments
The same tests run on local, staging and CI without code changes.
Playwright: config/env.ts + .env + baseURL in playwright.config.ts
- CoreTest data
Shared data makes tests depend on each other.
Playwright: Builders with faker; create data per test
- CoreIsolation and parallel runs
Independent tests can run in any order and at the same time.
Playwright: New browser context per test; fullyParallel and workers
- CoreTags and selective runs
A fast smoke set for every change, the full set on a schedule.
Playwright: @smoke / @regression with --grep
- CoreFailure evidence
A failed run must show what happened without re-running.
Playwright: Trace on first retry, screenshot and video on failure, HTML report
- CoreSecrets stay out of the repo
A leaked password in git history cannot be taken back.
Playwright: .env and .auth/ in .gitignore; .env.example committed; CI secrets
- CoreConventions and README
New teammates can run and extend the suite on day one.
Playwright: README with setup, naming rules and a review checklist
- RecommendedAuthentication reuse
Logging in through the UI before every test is slow and fragile.
Playwright: storageState from an API login in global setup
- CoreAPI for setup and cleanup
Preparing state by API is faster and more stable than clicking.
Playwright: request fixture or APIRequestContext
- RecommendedRetries and flaky policy
Retries hide real problems if nobody looks at them.
Playwright: retries only in CI; review tests that pass on retry
- RecommendedCode quality checks
Style and type errors are caught before review.
Playwright: tsc --noEmit, ESLint, Prettier
- RecommendedContinuous integration
Every change is checked the same way, on a clean machine.
Playwright: Smoke on pull request; regression on a schedule; upload report
- RecommendedReusable components
A header, toast or modal used on ten screens should be written once.
Playwright: components/ classes created inside page objects
- AdvancedCross-browser and remote runs
Covers browser differences once the core suite is stable.
Playwright: projects: chromium, firefox, webkit; optional sharding
- CoreTest report
After a run, anyone should open one file and see what passed, what failed and why.
Playwright: Built-in HTML reporter (npx playwright show-report); JUnit XML on CI
- AdvancedTrends and history
Trends and history help a larger team, not a first suite.
Playwright: Allure or a custom reporter on top of the HTML report
Avoid
Common mistakes and what to do instead
✗ Raw selectors and URLs inside spec files
✓ Put locators in page objects and URLs in config.
✗ page.waitForTimeout() to wait for the UI
✓ Use an action's auto-wait or a web-first expect().
✗ Tests that depend on the order they run
✓ Create the data each test needs in a fixture.
✗ Logging in through the UI in every test
✓ Log in once by API and reuse storageState.
✗ One huge Page Object for the whole app
✓ One class per screen, shared parts as components.
+All project files · download the complete starter project
tests/login.spec.ts
Auth happy path + client-side validation negative cases.
12345678910111213141516171819202122232425
import { test, expect } from 'playwright/test';
import { LoginPage } from '../pages/login.page';
test.describe('Authentication @smoke', () => {
test('demo credentials reach Bug Playground', async ({ page }) => {
const login = new LoginPage(page);
await login.goto();
await login.useDemoAccount();
await login.submit();
await expect(page).toHaveURL(/\/bug-playground\/\/?$/);
});
test('invalid email and short password show validation messages @regression', async ({
page,
}) => {
const login = new LoginPage(page);
await login.goto();
await login.signIn('not-an-email', 'short');
await expect(login.emailFormatError).toHaveText(/Use a valid email address/i);
await expect(login.passwordLengthError).toHaveText(
/Password must be at least 8/i,
);
});
});Run locally
Setup
- unzip/ → extract
qapractice.hakdogan.com.zip. - cd/ → enter
qapractice.hakdogan.com/. - install/ → run
npm install. - browsers/ → run
npx playwright install. - test/ → run
npx playwright test.
Usage
- report/ →
npx playwright show-report. - smoke/ →
npx playwright test --grep @smoke. - regression/ →
npx playwright test --grep @regression. - debug/ →
npx playwright test --debug. - node/ → Node.js v18+ (v20 recommended).