A personal browser automation and testing suite built with Playwright, targeting www.rajeshkr.com.
- Overview
- Prerequisites
- Installation
- Project Structure
- Configuration
- Running Tests
- Writing Tests
- Reports
- Tips & Tricks
playwright-browser-test is a personal Playwright project for automating and testing browser interactions on www.rajeshkr.com. It supports running tests across multiple browsers (Chromium, Firefox, WebKit) with built-in HTML reporting.
Make sure you have the following installed:
- Node.js v18 or higher
- npm v9 or higher (comes with Node.js)
Check versions:
node -v
npm -v# Clone if using version control
git clone <your-repo-url>
cd playwright-browser-test
# OR create fresh
mkdir playwright-browser-test
cd playwright-browser-test
npm init -ynpm init playwright@latestWhen prompted, choose:
TypeScriptorJavaScript(your preference)testsas the test directorytruefor GitHub Actions workflow (optional)trueto install browsers
npx playwright installTo install only specific browsers:
npx playwright install chromium
npx playwright install firefox
npx playwright install webkitplaywright-browser-test/
โโโ tests/ # Test files
โ โโโ example.spec.ts # Sample test for rajeshkr.com
โโโ playwright.config.ts # Playwright configuration
โโโ package.json
โโโ README.md
Edit playwright.config.ts to set up the base URL and browser targets:
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
retries: 1,
reporter: 'html',
use: {
baseURL: 'https://www.rajeshkr.com',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// Mobile viewports
{
name: 'mobile-chrome',
use: { ...devices['Pixel 5'] },
},
{
name: 'mobile-safari',
use: { ...devices['iPhone 13'] },
},
],
});npx playwright testnpx playwright test --headednpx playwright test tests/example.spec.tsnpx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkitnpx playwright test --debugnpx playwright test --uinpx playwright test -g "homepage loads correctly"Here's an example test targeting www.rajeshkr.com:
// tests/homepage.spec.ts
import { test, expect } from '@playwright/test';
test.describe('rajeshkr.com - Homepage', () => {
test('page loads and has correct title', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/Rajesh/i);
});
test('page is visible and has content', async ({ page }) => {
await page.goto('/');
await expect(page.locator('body')).toBeVisible();
});
test('no broken links on homepage', async ({ page }) => {
await page.goto('/');
const links = page.locator('a[href]');
const count = await links.count();
console.log(`Found ${count} links on homepage`);
});
test('page loads within 3 seconds', async ({ page }) => {
const start = Date.now();
await page.goto('/');
const duration = Date.now() - start;
expect(duration).toBeLessThan(3000);
});
test('page is responsive on mobile', async ({ page }) => {
await page.setViewportSize({ width: 375, height: 812 });
await page.goto('/');
await expect(page.locator('body')).toBeVisible();
});
});npx playwright show-reportThe report is saved to playwright-report/index.html by default.
npx playwright show-trace trace.zip| Task | Command |
|---|---|
| Codegen (record a test) | npx playwright codegen https://www.rajeshkr.com |
| List all tests | npx playwright test --list |
| Update browsers | npx playwright install |
| Run in CI mode | CI=true npx playwright test |
| Clear test cache | npx playwright test --no-cache |
npx playwright codegen https://www.rajeshkr.comThis opens a browser and records your interactions, auto-generating test code you can paste into your test files.
- ๐ Playwright Docs
- ๐ Playwright GitHub
- ๐ www.rajeshkr.com