How aftabahmed1/playwright-e2e-tests works
Main Components
• • Test Runner & Configuration: This includes the Playwright configuration file (playwright.config.ts) and package.json scripts that drive various test types (e.g., complete tests, UI-only, API-only, smoke, and regression).
• • UI Tests: Under the tests/UI directory, the project uses a Page Object Model. Each page (e.g., HomePage, LoginPage, CartPage, etc.) is modeled in its own file inside tests/UI/pages, and the end-to-end scenarios are defined in tests/UI/UI-tests.
• • API Tests: The tests/API directory contains test cases (e.g., users.spec.ts) that cover actions like creating, updating, and deleting users.
• • Utility Helpers: The helpers directory (e.g., UI.ts, userAPI.ts, token.ts, and types.ts) provides abstracted functions to standardize UI interactions and API requests.
• • Test Data: The fixtures directory holds data (e.g., productData.ts and testData.ts) that feed into both UI and API tests.
• • CI/CD Pipeline: The .github/workflows folder contains the GitHub Actions workflow (playwright.yml), automating test runs on every push/PR.
• • Containerization: Dockerfile and docker-compose.yml indicate that tests can be run in containerized environments.
Understand the Relationships and Data Flow
• The Playwright configuration ties the test suite together, interacting with both UI and API tests.
• UI Tests:
○ Use the Page Object Model to abstract page interactions. Each page component (like LoginPage or CheckoutPage) is represented as an object that encapsulates related functions.
○ The central test cases in tests/UI/UI-tests reference these page objects to mimic user flows (e.g., login, purchase flow).
• API Tests:
○ Use helper functions to handle tokens and API calls, ensuring the process of creating and managing users is standardized.
○ They also make use of test data from the fixtures directory.
• The CI/CD (GitHub Actions) and containerization (Docker) components help automate and standardize the test runs in various environments.
• Data flows from the environment (via .env using API_TOKEN) through configuration into both UI and API tests.
Architectural Patterns and Design Principles
• Separation of Concerns: Differentiated directories for UI and API tests ensure that each test type handles its responsibilities without overlap.
• Modularity: Helpers and fixtures abstract out common functionality and test data, promoting reusability and easier maintenance.
• POM for UI Tests: This design pattern makes the UI tests more maintainable and scalable.
• CI/CD Integration: Automated workflows ensure tests run on code changes, highlighting the continuous integration principles.
• Containerization: The Dockerfile and docker-compose support environment consistency, especially in distributed test runs.
Extra Detail Points
• Modularity by showing how each component interacts with changes in the API token or test data.
• To note that although each test type (UI/API) is separate, they share common utilities and configuration to maintain consistency across the testing suite.