# yanchunhuo/automationtest architecture

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

- Interactive diagram: https://gitdiagram.com/yanchunhuo/automationtest
- Repository: https://github.com/yanchunhuo/automationtest

## Overview

##### Project Type and Purpose
- This is a unified test automation framework supporting:
– API tests (via pytest + requests)
– Web UI tests (via pytest + selenium)
– Mobile App UI tests (via pytest + Appium, covering Android, iOS, Chrome on mobile, Windows)
– Performance tests (via Locust)
- It provides reusable base/client libraries, configuration management, page-object modules, test case definitions, and report generation.

##### High-Level Components
a. Test Orchestrators (CLI entry points)
– run_api_test.py
– run_web_ui_test.py
– run_app_ui_test.py
– run_app_ui_monkey_test.py
– start_locust_master.sh / start_locust_slave.sh
– generate_*_test_report.py
b. Configuration Layer
– config/*.conf & project-specific config under config/demoProject
– pojo/*_config.py classes that load/hold config
– init/* modules that bootstrap each test type (init/api, init/web_ui, etc.)
c. Core Libraries
– base/ (foundation classes for API, UI, performance)
– common/ (shared utilities: HTTP client, database clients, image tools, encryption, messaging, etc.)
– common_projects/ (project-specific business logic abstractions)
d. Test Assets
– cases/ (pytest test modules organized by type and project)
– page_objects/ (Page-Object Model definitions for UI tests)
– models/ (SQLite DB models for session or state persistence)
– test_data/ (static JSON or data files)
– packages/ (mobile app binaries & installers)
e. External Services & Tools
– Target system under test: API endpoints, Web applications, Mobile apps
– Selenium server, Appium server, Locust master/slave
– Databases: MySQL / Oracle / SQLite / Redis / Memcached
– Allure server for report hosting
– External message queues (Aliyun MNS, Zookeeper)
f. Reporting & Logging
– logs/test.log
– output/ (Allure result directories)
– generate_*_test_report.py scripts

##### Relationships & Data Flows
- The **runner scripts** read **config files**, invoke **init** modules, and launch pytest with the specified **cases/** directory.
- During test execution, pytest loads fixtures, uses **base/** and **common/** libraries to send HTTP requests or drive browsers/devices via Selenium/Appium.
- UI tests rely on **page_objects/** to locate elements and execute interactions.
- Test data flows from **test_data/** into test cases and may write state to **models/** (SQLite) or external DBs.
- Performance tests spawn Locust clients that hit the target API/web endpoint.
- All test logs and results are collected under **logs/** and **output/**.
- **generate_*_test_report.py** reads the output, invokes Allure to build HTML reports, and serves them.

##### Architectural Patterns & Principles
– **Layered Architecture**: separation of test orchestration, configuration loading, core libraries, and test assets.
– **Plugin-based** with pytest: test discovery, fixtures, markers, parallel execution via pytest-xdist.
– **Page-Object Model (POM)** for UI tests: clear separation of element definitions and test logic.
– **Factory/Client Abstraction** in base/api and base/app_ui: one client per project per platform.
– **Singleton/Configuration** pattern: pojo/*_config.py centralizes config parsing.
– **Modularization**: common code in common/, project‐specific overlays in common_projects/.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers and components
    subgraph "Orchestrator Layer" 
        direction TB
        RA["run_api_test.py"]:::script
        RW["run_web_ui_test.py"]:::script
        RU["run_app_ui_test.py"]:::script
        RM["run_app_ui_monkey_test.py"]:::script
        LM["start_locust_master.sh"]:::script
        LS["start_locust_slave.sh"]:::script
        GRAPI["generate_api_test_report.py"]:::script
        GRW["generate_web_ui_test_report.py"]:::script
        GRA["generate_app_ui_test_report.py"]:::script
        subgraph "Init Modules"
            direction TB
            AI["api_init.py"]:::init
            WI["web_ui_init.py"]:::init
            AUI["android_init.py"]:::init
            CUI["chrome_init.py"]:::init
            IUI["ios_init.py"]:::init
            WUI["windows_init.py"]:::init
            PFM["__init__.py"]:::init
        end
    end

    subgraph "Configuration Layer" 
        direction TB
        CFG["config/"]:::conf
        POJO["pojo/"]:::conf
    end

    subgraph "Core Library Layer" 
        direction TB
        PT["pytest Engine"]:::core
        BASE["base/"]:::core
        COMMON["common/"]:::core
        CP["common_projects/"]:::core
    end

    subgraph "Test Asset Layer" 
        direction TB
        CASES["cases/"]:::asset
        PO["page_objects/"]:::asset
        TD["test_data/"]:::asset
        MDL["models/"]:::asset
        PKG["packages/"]:::asset
        LOG["logs/test.log"]:::asset
        OUT["output/"]:::asset
    end

    subgraph "External Systems" 
        direction TB
        SUT["System Under Test"]:::ext
        SEL["Selenium/Appium/Locust"]:::ext
        DB["Databases & MQ"]:::ext
        AL["Allure Server"]:::ext
    end

    %% Connections
    RA -->|"invokes"| PT
    RW -->|"invokes"| PT
    RU -->|"invokes"| PT
    RM -->|"invokes"| PT
    LM -->|"starts performance"| SEL
    LS -->|"starts performance"| SEL

    RA -->|"load config"| CFG
    PT -->|"load config POJOs"| POJO
    PT -->|"use core libs"| BASE
    PT -->|"use core libs"| COMMON
    PT -->|"use core libs"| CP

    PT -->|"discover tests"| CASES
    PT -->|"use POM"| PO
    PT -->|"load data"| TD
    PT -->|"persist state"| MDL
    PT -->|"use packages"| PKG

    PT -->|"control browsers/apps"| SEL
    SEL -->|"responses"| PT

    BASE -->|"HTTP Request"| SUT
    BASE -->|"DB Read/Write"| DB
    COMMON -->|"Utility DB"| DB

    PT -->|"write logs"| LOG
    PT -->|"write results"| OUT

    OUT -->|"test data"| AL
    GRAPI -->|"read results"| OUT
    GRAPI -->|"publish report"| AL
    GRW -->|"read results"| OUT
    GRW -->|"publish report"| AL
    GRA -->|"read results"| OUT
    GRA -->|"publish report"| AL

    %% Click Events
    click RA "https://github.com/yanchunhuo/automationtest/blob/master/run_api_test.py"
    click RW "https://github.com/yanchunhuo/automationtest/blob/master/run_web_ui_test.py"
    click RU "https://github.com/yanchunhuo/automationtest/blob/master/run_app_ui_test.py"
    click RM "https://github.com/yanchunhuo/automationtest/blob/master/run_app_ui_monkey_test.py"
    click LM "https://github.com/yanchunhuo/automationtest/blob/master/start_locust_master.sh"
    click LS "https://github.com/yanchunhuo/automationtest/blob/master/start_locust_slave.sh"
    click GRAPI "https://github.com/yanchunhuo/automationtest/blob/master/generate_api_test_report.py"
    click GRW "https://github.com/yanchunhuo/automationtest/blob/master/generate_web_ui_test_report.py"
    click GRA "https://github.com/yanchunhuo/automationtest/blob/master/generate_app_ui_test_report.py"
    click CFG "https://github.com/yanchunhuo/automationtest/tree/master/config/"
    click POJO "https://github.com/yanchunhuo/automationtest/tree/master/pojo/"
    click AI "https://github.com/yanchunhuo/automationtest/blob/master/init/api/api_init.py"
    click WI "https://github.com/yanchunhuo/automationtest/blob/master/init/web_ui/web_ui_init.py"
    click AUI "https://github.com/yanchunhuo/automationtest/blob/master/init/app_ui/android/android_init.py"
    click CUI "https://github.com/yanchunhuo/automationtest/blob/master/init/app_ui/chrome/chrome_init.py"
    click IUI "https://github.com/yanchunhuo/automationtest/blob/master/init/app_ui/ios/ios_init.py"
    click WUI "https://github.com/yanchunhuo/automationtest/blob/master/init/app_ui/windows/windows_init.py"
    click PFM "https://github.com/yanchunhuo/automationtest/blob/master/init/performance/__init__.py"
    click BASE "https://github.com/yanchunhuo/automationtest/tree/master/base/"
    click COMMON "https://github.com/yanchunhuo/automationtest/tree/master/common/"
    click CP "https://github.com/yanchunhuo/automationtest/tree/master/common_projects/"
    click CASES "https://github.com/yanchunhuo/automationtest/tree/master/cases/"
    click PO "https://github.com/yanchunhuo/automationtest/tree/master/page_objects/"
    click TD "https://github.com/yanchunhuo/automationtest/tree/master/test_data/"
    click MDL "https://github.com/yanchunhuo/automationtest/tree/master/models/"
    click PKG "https://github.com/yanchunhuo/automationtest/tree/master/packages/"
    click LOG "https://github.com/yanchunhuo/automationtest/blob/master/logs/test.log"

    %% Styles
    classDef script fill:#D0E6FF,stroke:#0275d8
    classDef init fill:#E8F5E9,stroke:#388E3C
    classDef conf fill:#E8F0E8,stroke:#4CAF50
    classDef core fill:#FFE0B2,stroke:#FB8C00
    classDef asset fill:#E1BEE7,stroke:#9C27B0
    classDef ext fill:#F5F5F5,stroke:#9E9E9E,stroke-dasharray: 5 2
```
