# aftabahmed1/playwright-e2e-tests architecture

> Architecture diagram of the GitHub repository aftabahmed1/playwright-e2e-tests, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aftabahmed1/playwright-e2e-tests
- Repository: https://github.com/aftabahmed1/playwright-e2e-tests

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    H["CI/CD Pipeline"]:::cicd
    click H "https://github.com/aftabahmed1/playwright-e2e-tests/blob/master/.github/workflows/playwright.yml"
    
    %% Containerization Subgraph
    subgraph "Containerization"
        I1["Dockerfile"]:::container
        I2["docker-compose.yml"]:::container
    end
    click I1 "https://github.com/aftabahmed1/playwright-e2e-tests/tree/master/Dockerfile"
    click I2 "https://github.com/aftabahmed1/playwright-e2e-tests/blob/master/docker-compose.yml"

    %% Test Runner & Configuration Subgraph
    subgraph "Test Runner & Configuration"
        A["playwright.config.ts"]:::config
        B["package.json"]:::config
    end
    click A "https://github.com/aftabahmed1/playwright-e2e-tests/blob/master/playwright.config.ts"
    click B "https://github.com/aftabahmed1/playwright-e2e-tests/blob/master/package.json"

    %% UI Tests with POM Subgraph
    subgraph "UI Tests with POM"
        C["UI Test Cases"]:::ui
        D["Page Objects"]:::ui
    end
    click C "https://github.com/aftabahmed1/playwright-e2e-tests/tree/master/tests/UI/UI-tests"
    click D "https://github.com/aftabahmed1/playwright-e2e-tests/tree/master/tests/UI/pages"

    %% API Tests Node
    E["API Test Cases"]:::api
    click E "https://github.com/aftabahmed1/playwright-e2e-tests/blob/master/tests/API/users.spec.ts"

    %% Shared Components Subgraph
    subgraph "Shared Components"
        F["Utility Helpers"]:::helper
        G["Test Data"]:::data
    end
    click F "https://github.com/aftabahmed1/playwright-e2e-tests/tree/master/helpers"
    click G "https://github.com/aftabahmed1/playwright-e2e-tests/tree/master/fixtures"

    %% Connections from CI/CD and Containerization to Test Runner & Configuration
    H --> A
    H --> B
    I1 --> A
    I1 --> B
    I2 --> A
    I2 --> B

    %% Connections from Test Runner & Configuration to UI and API Tests
    A --> C
    B --> C
    A --> E
    B --> E

    %% UI Tests internal connection
    C --> D

    %% Connections from Tests to Shared Components
    C --> F
    C --> G
    E --> F
    E --> G

    %% Styles
    classDef cicd fill:#FAD7A0,stroke:#000,stroke-width:2px;
    classDef container fill:#AED6F1,stroke:#000,stroke-width:2px;
    classDef config fill:#A9DFBF,stroke:#000,stroke-width:2px;
    classDef ui fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef api fill:#F5B7B1,stroke:#000,stroke-width:2px;
    classDef helper fill:#D2B4DE,stroke:#000,stroke-width:2px;
    classDef data fill:#F7DC6F,stroke:#000,stroke-width:2px;
```
