A collection of Playwright end-to-end tests demonstrating the basics of automated testing. This project covers key concepts such as test execution, element locators, assertions, debugging, screenshots, and more.
- Prerequisites
- Installation
- Running the Tests
- Writing a Test
- Debugging Tips
- Screenshots & Videos
- Continuous Integration
- Contributing
- License
-
Clone the repository:
git clone https://github.com/yourusername/Playwright_testing.git cd Playwright_testing
-
Install dependencies:
npm install
-
Install Playwright browsers (if not already installed):
npx playwright install
-
Run all tests:
npx playwright test
-
Run a specific test file:
npx playwright test tests/example.spec.ts
-
Run tests in headed mode (visible browser):
npx playwright test --headed
-
Run tests in debug mode:
npx playwright test --debug
-
Run tests in a specific browser (Chromium, Firefox, or WebKit):
npx playwright test --project=chromium
Example test file: tests/example.spec.ts
import { test, expect } from '@playwright/test';
test('basic navigation test', async ({ page }) => {
await page.goto('https://playwright.dev');
await expect(page).toHaveTitle(/Playwright/);
});
Run the test with:
npx playwright test tests/example.spec.ts
-
Use the Playwright Inspector:
npx playwright test --debug
-
Pause execution in a test:
await page.pause();
-
Use VS Code breakpoints for interactive debugging.
-
Capture a screenshot:
await page.screenshot({ path: 'screenshot.png' });
-
Record a video (configure in your test or Playwright config):
test.use({ video: 'on' });
Playwright is CI-friendly. For example, you can set up GitHub Actions with a workflow like this:
name: Playwright Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
- run: npm install
- run: npx playwright install
- run: npx playwright test
Place this in .github/workflows/playwright.yml
.
Contributions are welcome! Please fork the repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.
Happy Testing! 🚀
This README gives a clear guide on how to set up and work with your Playwright tests, making it easier for collaborators to get started. Let me know if you need any adjustments!