# s3cur3/phoenix_test_playwright architecture

> Architecture diagram of the GitHub repository s3cur3/phoenix_test_playwright, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/s3cur3/phoenix_test_playwright
- Repository: https://github.com/s3cur3/phoenix_test_playwright

## Overview

##### Main Components Identification

a) Phoenix Test Integration Layer
- This at the top level as it's the main entry point
- Represented by `PhoenixTest.Case`

b) Playwright Integration Layer
- Core component handling browser automation
- Contains multiple sub-components from the `lib/phoenix_test/playwright/` directory

c) Browser Communication Layer
- Handles the actual communication with browsers
- Includes Port and Connection management

##### Component Relationships

**[Phoenix Application Under Test] ←→ [PhoenixTest Layer]**
- ↑                         ↓
- ↑                  [Playwright Layer]
- ↑                         ↓
- ←    [Browser Interface Layer]
- ↓
- [Actual Browser Instance]

##### Detailed Component Breakdown

For the Playwright Layer, show these key components:
- Browser Management (`browser.ex`)
- Context Management (`browser_context.ex`)
- Frame Handling (`frame.ex`)
- Selector Logic (`selector.ex`)
- Message Processing (`message.ex`)
- Serialization (`serialization.ex`)

##### Communication Flow

- Command flow from Phoenix Test → Playwright
- Response flow from Browser → Phoenix Test
- Port communication between Elixir and Playwright

##### Important Elements

a) Core Components:
**[PhoenixTest.Case] → [Playwright] → [Browser]**

b) Integration Points:
- Port Communication
- Message Serialization
- Browser Context Management

c) Test Support Infrastructure:
- Endpoint
- Router
- Controllers/LiveViews

##### Technical Details to Note

Specific technical aspects:
- Port-based communication system
- Browser context isolation
- Selector strategy implementation
- Message serialization/deserialization

##### Architectural Patterns to Highlight
- Command pattern for browser interactions
- Bridge pattern between Elixir and Playwright
- Factory pattern for browser/context creation

Remember to include:
- Version compatibility information
- Configuration points
- Test execution flow
- Error handling paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Phoenix
        TestCase["PhoenixTest.Case"]
        TestEndpoint["Test Endpoint"]
        TestRouter["Test Router"]
        subgraph Controllers
            TestControllers["Controllers"]
            TestViews["Views"]
            TestLiveViews["LiveViews"]
        end
    end

    subgraph PlaywrightLayer
        Browser["Browser Management"]
        Context["Context Management"]
        Frame["Frame Handling"]
        Selector["Selector Logic"]
        Message["Message Processing"]
        Serial["Serialization"]
    end

    subgraph Communication
        Port["Port Communication"]
        Conn["Connection Management"]
    end

    subgraph BrowserInstance
        ActualBrowser["Browser Instance"]
    end

    %% Relationships
    TestCase --> TestEndpoint
    TestEndpoint --> TestRouter
    TestRouter --> TestControllers
    TestRouter --> TestViews
    TestRouter --> TestLiveViews
    
    TestCase --> PlaywrightLayer
    
    Browser --> Context
    Context --> Frame
    Frame --> Selector
    Message --> Serial
    
    PlaywrightLayer --> Communication
    Communication --> ActualBrowser
    ActualBrowser -.-> Communication
    Communication -.-> PlaywrightLayer
    PlaywrightLayer -.-> TestCase

    %% Click Events
    click TestCase "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/case.ex"
    click Browser "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/browser.ex"
    click Context "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/browser_context.ex"
    click Frame "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/frame.ex"
    click Selector "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/selector.ex"
    click Message "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/message.ex"
    click Serial "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/serialization.ex"
    click Port "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/port.ex"
    click Conn "https://github.com/s3cur3/phoenix_test_playwright/blob/main/lib/phoenix_test/playwright/connection.ex"
    click TestEndpoint "https://github.com/s3cur3/phoenix_test_playwright/blob/main/test/support/endpoint.ex"
    click TestRouter "https://github.com/s3cur3/phoenix_test_playwright/blob/main/test/support/router.ex"
    click TestControllers "https://github.com/s3cur3/phoenix_test_playwright/blob/main/test/support/page_controller.ex"
    click TestViews "https://github.com/s3cur3/phoenix_test_playwright/blob/main/test/support/page_view.ex"
    click TestLiveViews "https://github.com/s3cur3/phoenix_test_playwright/blob/main/test/support/index_live.ex"

    %% Styling
    classDef phoenix fill:#3498db,stroke:#2980b9,color:white
    classDef playwright fill:#2ecc71,stroke:#27ae60,color:white
    classDef communication fill:#e67e22,stroke:#d35400,color:white
    classDef browser fill:#95a5a6,stroke:#7f8c8d,color:white

    class TestCase,TestEndpoint,TestRouter,TestControllers,TestViews,TestLiveViews phoenix
    class Browser,Context,Frame,Selector,Message,Serial playwright
    class Port,Conn communication
    class ActualBrowser browser
```
