Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zahid-automate/playwright-fixtures

Use of Fixtures in Playwright
https://github.com/zahid-automate/playwright-fixtures

playwright playwright-typescript

Last synced: 14 days ago
JSON representation

Use of Fixtures in Playwright

Awesome Lists containing this project

README

        

𝟭. 𝗙𝗶𝘅𝘁𝘂𝗿𝗲 𝗗𝗲𝗳𝗶𝗻𝗶𝘁𝗶𝗼𝗻:
- We create custom fixtures by extending Playwright's base test
- We define three fixtures: 'index.fixtures.ts and `auth.fixtures.ts` and `test-data.fixtures.ts`

**auth.fixtures.ts**:

 • Defines page-related fixtures (`loginPage`, `loggedInPage`)

 • Handles authentication state

 • Manages cleanup after tests

**test-data.fixtures.ts**:

 • Contains all test data

 • Makes test data reusable

 • Easy to maintain test data in one place

**index.ts**:

 • Central point for importing fixtures

 • Makes test files cleaner

 • Re-exports all necessary test components

𝟮. 𝗕𝗲𝗻𝗲𝗳𝗶𝘁𝘀:
- Reduces code duplication
- Makes tests cleaner and more maintainable
- Centralizes common setup and teardown logic
- Ensures consistent test state

𝟯. 𝗕𝗲𝘀𝘁 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗲𝘀:
- Fixtures are defined in a separate file
- Each fixture has clear setup and cleanup phases
- Fixtures can depend on other fixtures

The purpose of index.ts is to:

• Import and re-export all fixtures and utilities

• Provide a single entry point for importing test dependencies

• Make test files cleaner with consolidated imports

Without index.ts, you would need multiple imports in each test file.


🎭 Why I Prefer Playwright Fixtures Over Storage State for E2E Testing

After extensive testing, here's why fixtures are my go-to choice:

✨ Key Benefits:
- Better test isolation - each test starts fresh
- Dynamic data handling - perfect for real-world scenarios
- Reusable setup/teardown logic across test suites
- Parameterizable - easily customize per test case
- Type-safe with TypeScript support

💡 Pro Tip: While storage state is great for simple auth flows, fixtures shine in complex scenarios where you need:
- Dynamic user data
- Complex test environments
- Detailed setup/teardown processes
- Shared testing utilities

Real talk: Storage state has its place, but fixtures give you that extra control and flexibility that modern web testing demands.

## Video grab showing test results
[screen-capture (17).webm](https://github.com/user-attachments/assets/5c71c1a1-e7d3-4c96-87b0-605fc9f501bc)